Joiner
解决字符串连接问题
// a,b,null,c
String join = String.join(",", "a", "b", null,"c");
System.out.println(join);
// a,b,c
String join1 = Joiner.on(",").skipNulls().join("a", "b", null, "c");
System.out.println(join1);
// a,b,default,c
String join2 = Joiner.on(",").useForNull("default").join("a", "b", null, "c");
System.out.println(join2);
Strings
String a = "abcdef";
String b = "abcghi";
// abc
System.out.println( Strings.commonPrefix(a,b));
String c = "abcghi";
String d = "defghi";
// ghi
System.out.println(Strings.commonSuffix(c,d));
// 互转null与""
System.out.println(Strings.nullToEmpty(null));
System.out.println(Strings.emptyToNull(""));
// false
System.out.println(Strings.isNullOrEmpty(" "));
// true
System.out.println(Strings.isNullOrEmpty(""));
// 00abc
System.out.println(Strings.padStart("abc", 5, '0'));
// abc00
System.out.println(Strings.padEnd("abc", 5, '0'));
// aaaaa
System.out.println(Strings.repeat("a", 5));
com.google.common.base.Charsets
定义一些常用字符集常量,不建议去手动写
public final class Charsets {
@GwtIncompatible
public static final Charset US_ASCII = Charset.forName("US-ASCII");
@GwtIncompatible
public static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1");
public static final Charset UTF_8 = Charset.forName("UTF-8");
@GwtIncompatible
public static final Charset UTF_16BE = Charset.forName("UTF-16BE");
@GwtIncompatible
public static final Charset UTF_16LE = Charset.forName("UTF-16LE");
@GwtIncompatible
public static final Charset UTF_16 = Charset.forName("UTF-16");
private Charsets() {
}
}