Java 基础操作库 hoe 使用介绍

hoe基本介绍

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

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

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

JDK 版本需要 1.6 以上

github 源码地址:https://github.com/caspar-chen/hoe

文档地址:https://caspar-chen.github.io/hoe/

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


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


使用
NumberHoe 数字处理工具
//最大公约数
System.out.println(NumberHoe.gcd(2,8));//result = 2
System.out.println(NumberHoe.gcd(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.println(NumberHoe.toCNMontrayUnit(new BigDecimal(123.45)));// result = 壹佰贰拾叁元肆角伍分
//将金额转换为汉语中人民币的大写
System.out.println(NumberHoe.toCNMontrayUnit("-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.println(StringHoe.collapseWhitespace("a     b c"));	//result = "a b c"

//一个字符串在另一个字符串中出现的次数
System.out.println(StringHoe.countMatches("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.println(StringHoe.trim(" a b "));//result = "a b"

//去除所有的空格,制表符等
System.out.println(StringHoe.trimAll(" a 	b c "));//result = "abc"

//去除字符串开头的空格
System.out.println(StringHoe.trimLeft(" a b "));//result = "a b "

//去除字符串结尾的空格
System.out.println(StringHoe.trimRight(" 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.println(StringHoe.toCamelCase("hello world"));//result = helloWorld

//转换成Studly命名法 (所有单词首字母大写)
System.out.println(StringHoe.toStudlyCase("hello world"));//result = HelloWorld

//反驼峰命名法 (所有单词首字母小写),用指定字符串拼接
System.out.println(StringHoe.toDecamelize("hello world","-"));//result = hello-world
System.out.println(StringHoe.toDecamelize("hello world",null));//result = hello world
		
//蛇行命名法 (所有单词首字母小写,下划线分割)
System.out.println(StringHoe.toSnakeCase("hello world"));//result = hello_world

//将字符串按行(\r\n)转换成数组
StringHoe.lines("hello\r world"); //result = {"hello","world"}

//反转字符串 abc -> cba
System.out.println(StringHoe.reverse("abc"));//result = cba

//将字符串重复多少次
System.out.println(StringHoe.repeat("hoe", 3));//result = hoehoehoe

//将字符串重复多少次,并用指定字符串隔开
System.out.println(StringHoe.repeat("hoe", "-", 3));//result = hoe-hoe-hoe

//删除第一个字符
System.out.println(StringHoe.removeFirst("hoe"));	// result = oe

//删除最后一个字符
System.out.println(StringHoe.removeLast("hoe"));	// result = ho

//所有非数字,字母,下划线的字符
System.out.println(StringHoe.removeNonWords("中国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));

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

五只鸭子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值