Guava---Strings

文章目录

    • 字符emptyToNull
    • 字符nullToEmpty
    • 获取字符公同前缀
    • 复制字符串
    • 判断字符串是否为空
    • 补字符串

字符emptyToNull

 String s = Strings.emptyToNull("");

字符nullToEmpty

 String s2 = Strings.nullToEmpty(null);

获取字符公同前缀

 String s3 = Strings.commonPrefix("asc","ascvv");

复制字符串

 String s5 = Strings.repeat("asc11",3);

判断字符串是否为空

  boolean s6 = Strings.isNullOrEmpty("");

补字符串

String s7 = Strings.padStart("abc", 4, 'f');
System.out.println("长度不够,在前面补字符: " + s7); //fabc

String s8 = Strings.padEnd("abc", 4, 'f');
System.out.println("长度不够,在后面补字符: " + s8); //abcf

你可能感兴趣的:(Guava)