Java 基础操作库 hoe 使用介绍

阅读: 评论:0

Java 基础操作库 hoe 使用介绍

Java 基础操作库 hoe 使用介绍

hoe基本介绍

hoe 是一个 Java 基础操作库,包括 String,number,random 等常规操作,几乎包含了大部分工作中用到的常用处理方法,也有详细文档。

可以使用 Hoe 来轻松解决字符串,数字,随机数等的处理。

整个包不依赖任何其他第三方库,也极其简单小巧,只有 18kb。

JDK 版本需要 1.6 以上

github 源码地址:

文档地址:/

引用
jar 包托管在 maven 中央仓库,如果你使用了 maven,可以直接轻松引用



<dependency><groupId>com.github.caspar-chen</groupId><artifactId>hoe</artifactId><version>0.0.2</version></dependency>


使用
NumberHoe 数字处理工具
//最大公约数
System.out.d(2,8));//result = 2
System.out.d(12,16,40));//result = 4//最小公倍数
System.out.println(NumberHoe.lcm(2,3));//result = 6
System.out.println(NumberHoe.lcm(2,6,22));//result = 66//是否是负整数
System.out.println(NumberHoe.isNegativeInteger("-1"));//result = true//是否是非负整数,(包括0和正整数)
System.out.println(NumberHoe.isNonNegativeInteger("-1"));//result = false//是否是正整数
System.out.println(NumberHoe.isPositiveInteger("22"));//result = true//是否是非正整数,(包括0和负整数)
System.out.println(NumberHoe.isNonPositiveInteger("0"));//result = true//将金额转换为汉语中人民币的大写
System.out.CNMontrayUnit(new BigDecimal(123.45)));// result = 壹佰贰拾叁元肆角伍分
//将金额转换为汉语中人民币的大写
System.out.CNMontrayUnit("-4500.23")); //result = 负肆仟伍佰元零贰角叁分

StringHoe 字符串操作
//拼接任意数量字符串
System.out.println(StringHoe.append("h","o","e"));	//result = "hoe"
//在第一个字符串之前拼接任意数量字符串
System.out.println(StringHoe.appendPre("h","o","e"));	//result = "oeh"//将连续的多个空格替换成一个空格
System.out.llapseWhitespace("a     b c"));	//result = "a b c"//一个字符串在另一个字符串中出现的次数
System.out.untMatches("bobolab", "bo"));	//result = 2//将html实际符号转换成十进制的代码
System.out.println(StringHoe.htmlDecodeDecimalCode("<a>♣</a>"));	//result = "<a>♣</a>"//将html十进制的代码转换成 html实际符号
System.out.println(StringHoe.htmlEncodeByDecimalCode("<a>♣</a>"));	//result = "<a>♣</a>"//将html实际符号转换成html编码符号
System.out.println(StringHoe.htmlDecodeHtmlCode("<a>♣</a>"));	//result = "<a>♣</a>"//将html编码符号转换成 html实际符号
System.out.println(StringHoe.htmlEncodeByHtmlCode("<a>♣</a>"));	//result = "<a>♣</a>"//判断是否为null,或空字符串,或全是空格,或为大小写的字符串 "null"
System.out.println(StringHoe.isEmpty(" ")); //result = true//判断是否不为空 isEmpty的想反结果
System.out.println(StringHoe.isNotEmpty(" ")); //result = false//将字符串md5加密为32位的字符串
System.out.println(StringHoe.md5Bit32("要加密的字符串"));//result = cbdabf4eaccbec399cb73bf63748882f//将字符串md5加密为16位的字符串
System.out.println(StringHoe.md5Bit16("要加密的字符串"));//result = accbec399cb73bf6//去除字符串开头和结尾的空格
System.out.im(" a b "));//result = "a b"//去除所有的空格,制表符等
System.out.imAll(" a 	b c "));//result = "abc"//去除字符串开头的空格
System.out.imLeft(" a b "));//result = "a b "//去除字符串结尾的空格
System.out.imRight(" a b "));//result = " a b"//从左边开始截取字符串,截取2位
System.out.println(StringHoe.left("abc", 2));//result = ab//从右边开始截取字符串,截取2位
System.out.println(StringHoe.right("abc", 2));//result = bc//截取字符串,指定下标和截取位数,下标从0开始
System.out.println(StringHoe.mid("abcdef", 1, 3));//result = bcd//组合数组,将数组用指定分隔符去组合成String字符串(此方法提供各种参数类型的重载)
String[] arr = {"a","b","c","d"};
System.out.println(StringHoe.join(arr, "-"));//result = a-b-c-d//在字符串前面加上另一个字符串,如,在561前面补0,补足5位
System.out.println(StringHoe.padLeft("561", "0", 5));//result = 00561//在字符串后面加上另一个字符串,如,在561后面补0,补足5位
System.out.println(StringHoe.padRight("561", "0", 5));//result = 56100//转换成驼峰命名法
System.out.CamelCase("hello world"));//result = helloWorld//转换成Studly命名法 (所有单词首字母大写)
System.out.StudlyCase("hello world"));//result = HelloWorld//反驼峰命名法 (所有单词首字母小写),用指定字符串拼接
System.out.Decamelize("hello world","-"));//result = hello-world
System.out.Decamelize("hello world",null));//result = hello world//蛇行命名法 (所有单词首字母小写,下划线分割)
System.out.SnakeCase("hello world"));//result = hello_world//将字符串按行(rn)转换成数组
StringHoe.lines("hellor world"); //result = {"hello","world"}//反转字符串 abc -> cba
System.out.verse("abc"));//result = cba//将字符串重复多少次
System.out.peat("hoe", 3));//result = hoehoehoe//将字符串重复多少次,并用指定字符串隔开
System.out.peat("hoe", "-", 3));//result = hoe-hoe-hoe//删除第一个字符
System.out.veFirst("hoe"));	// result = oe//删除最后一个字符
System.out.veLast("hoe"));	// result = ho//所有非数字,字母,下划线的字符
System.out.veNonWords("中国hoe*—_♣"));	// result = hoe_//首字母大写
System.out.println(StringHoe.upperFirst("hoe"));// result = Hoe//首字母小写
System.out.println(StringHoe.lowerFirst("Hoe"));// result = hoe

RandomHoe 随机操作
//获取随机32位小写的UUID
System.out.println(RandomHoe.uuid());//获取随机32位大写的UUID
System.out.println(RandomHoe.uuidUpper());//获取随机16位小写的UUID
System.out.println(RandomHoe.uuidBit16());//获取随机16位大写的UUID
System.out.println(RandomHoe.uuidBit16Upper());//获取随机数,0到4 ,不包括5
System.out.println(RandomHoe.random(5));//获取范围内的随机数,10到49,不包括50
System.out.println(RandomHoe.random(10,50));//获取N位的随机数字,例子18位
System.out.println(RandomHoe.randomLimit(18));//随机取数组或集合中的一个,此方法有多种参数类型重载
int[] iarr = {1,2,3,4,5};
System.out.println(RandomHoe.randomGet(iarr));

本文发布于:2024-01-30 16:44:31,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170660427221421.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:操作   基础   Java   hoe
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23