Guava 之 Strings工具类

Strings类提供了一些实用的方法,使得我们能写出更为简洁优美的代码

如方法padStart()向前填充、padEnd()向后填充,commonPrefix()从前置获取,repeat()重复字符串n次,isNullOrEmpty()判空

		print("Strings.padStart : ", Strings.padStart("12345", 6, '&'), "\n", "Strings.padEnd : ",
				Strings.padEnd("12345", 6, '*'), "\n");
		print("Strings.commonPrefix :", Strings.commonPrefix("123456", "12"), "\n");
		print("Strings.commonSuffix :", Strings.commonSuffix("123456", "56"), "\n");
		print("Strings.repeat :",Strings.repeat("123456", 2), "\n");
		print("Strings.isNullOrEmpty :",Strings.isNullOrEmpty(null));

运行结果

Strings.padStart : &12345
Strings.padEnd : 12345*
Strings.commonPrefix :12
Strings.commonSuffix :56
Strings.repeat :123456123456
Strings.isNullOrEmpty :true

 

你可能感兴趣的:(guava)