对字符串为null或空的处理

Guava 提供了一系列用于字符串处理的工具:

  1. nullToEmpty(@Nullable String string):如果非空,则返回给定的字符串;否则返回空字符串

    java

    public static String nullToEmpty(@Nullable String string) {
        //如果string为null则返回空字符串,否则返回给定的string
        return string == null ? "" : string;
    }
  2. .isNullOrEmpty(@Nullable String string):如果字符串为空或长度为0返回true,否则返回false

    java

    public static boolean isNullOrEmpty(@Nullable String string) {
        return string == null || string.length() == 0;
    }
  3. emptyToNull(@Nullable String string):如果非空,则返回给定的字符串;否则返回null

    java

    public static String emptyToNull(@Nullable String string) {
        //调用isNullOrEmpty方法,如果返回true则return null,否则返回原字符串
        return isNullOrEmpty(string)?null:string;
    }
生成指定字符串的字符串副本
  1. padStart(String string, int minLength, char padChar):根据传入的minLength进行补充,如果minLength小于原来字符串的长度,则直接返回原来字符串,否则在字符串开头添加string.length() - minLength个padChar字符

    java

    public static String padStart(String string, int minLength, char padChar) {
        //使用Preconditions工具类进行字符串验空处理   
        Preconditions.checkNotNull(string);
        //如果原字符串长度大于传入的新长度则直接返回原字符串
        if(string.length() >= minLength) {
            return string;
        } else { //否则
            StringBuilder sb = new StringBuilder(minLength);
            //先在字符串前面添加string.length()-minLength个padChar字符
            for(int i = string.length(); i < minLength; ++i) {
                sb.append(padChar);
            }
            //最后将原始字符串添加到尾部
            sb.append(string);
            return sb.toString();
        }
    }
  2. padEnd(String string, int minLength, char padChar):根据传入的minLength进行补充,如果minLength小于原来字符串的长度,则直接返回原来字符串,否则在字符串结尾添加 string.length() - minLength 个padChar字符

 http://tskqn.b2b.h3cw.com
http://hzwxbgl2.b2b.h3cw.com
http://dkkqn.b2b.h3cw.com
http://hzsmsbgl2.b2b.h3cw.com
http://mlydnbx.b2b.h3cw.com
http://blkqn.b2b.h3cw.com
http://hzhdbgl4.b2b.h3cw.com
http://bsozzxgl2.b2b.h3cw.com
http://alsdkqn.b2b.h3cw.com
http://hzghzjbgl2.b2b.h3cw.com
http://gtkqn.b2b.h3cw.com
http://hzdlsmbgl2.b2b.h3cw.com
http://hdkqn.b2b.h3cw.com
http://bjbgl3.b2b.h3cw.com
http://hzkllbgl2.b2b.h3cw.com
http://adskqn.b2b.h3cw.com
http://prsdkqn.b2b.h3cw.com
http://hzfllbgl2.b2b.h3cw.com
http://sdfbgl2.b2b.h3cw.com
http://jtkqn.b2b.h3cw.com
http://hzfsmbgl2.b2b.h3cw.com
http://gdlmbgl3.b2b.h3cw.com
http://xsdkqn.b2b.h3cw.com
http://lyjkqn.b2b.h3cw.com
http://hznlbgl2.b2b.h3cw.com
http://zykqn.b2b.h3cw.com
http://hzxssbgl2.b2b.h3cw.com
http://cgkqn.b2b.h3cw.com
http://wklgl.b2b.h3cw.com
http://hzymbgl3.b2b.h3cw.com
http://mtlkqn.b2b.h3cw.com
http://hzgdlmbgl2.b2b.h3cw.com
http://snrsq.b2b.h3cw.com
http://hebx.b2b.h3cw.com
http://pwrsq.b2b.h3cw.com
http://hembgl4.b2b.h3cw.com
http://hzbltbgl3.b2b.h3cw.com
http://glrsq.b2b.h3cw.com
http://hzwnbgl2.b2b.h3cw.com
http://hemgl2.b2b.h3cw.com
http://fnrsq.b2b.h3cw.com
http://hzbsbgl3.b2b.h3cw.com
http://wklbgl3.b2b.h3cw.com
http://hersq2.b2b.h3cw.com
http://mjssjgl.b2b.h3cw.com
http://hzalsdbgl2.b2b.h3cw.com
http://mdrsq.b2b.h3cw.com
http://hzhdbgl3.b2b.h3cw.com
http://htcrsq.b2b.h3cw.com
http://hzlnbgl2.b2b.h3cw.com
http://wmgkqn.b2b.h3cw.com
http://snkqn.b2b.h3cw.com
http://alsdgl.b2b.h3cw.com
http://hzdzxyj2.b2b.h3cw.com
http://pwkqn.b2b.h3cw.com
http://ymgl2.b2b.h3cw.com
http://hzjlxyj2.b2b.h3cw.com
http://glkqn.b2b.h3cw.com
http://fnkqn.b2b.h3cw.com
http://hzxyj4.b2b.h3cw.com
http://hekqn.b2b.h3cw.com
http://mdkqn.b2b.h3cw.com
http://ddsgl2.b2b.h3cw.com
http://hzxyj3.b2b.h3cw.com
http://htckqn.b2b.h3cw.com
http://hzsyxyj2.b2b.h3cw.com
http://xpdsj.b2b.h3cw.com
http://hzxtexyj2.b2b.h3cw.com
http://sblgl.b2b.h3cw.com
http://sxdsj2.b2b.h3cw.com
http://hzbsxyj4.b2b.h3cw.com
http://bsdn6.b2b.h3cw.com
http://sxdsj.b2b.h3cw.com
http://hzhxxyj2.b2b.h3cw.com
http://fgddsbgl.b2b.h3cw.com
http://ddsgl.b2b.h3cw.com
http://hzmdjcz2.b2b.h3cw.com
http://tlzykt2.b2b.h3cw.com
http://hzsgjcz2.b2b.h3cw.com
http://fsmdq.b2b.h3cw.com
http://whgf.b2b.h3cw.com
http://sndsj.b2b.h3cw.com
http://hzwxrqz2.b2b.h3cw.com
http://bsbs.b2b.h3cw.com
http://hzoyrqz2.b2b.h3cw.com
http://ym2.b2b.h3cw.com
http://ygbkbx.b2b.h3cw.com
http://hzalsdrqz2.b2b.h3cw.com
http://wnbglgf.b2b.h3cw.com
http://hzoprqz2.b2b.h3cw.com
http://wnbgl4.b2b.h3cw.com
http://hzyxrqz2.b2b.h3cw.com
http://slbx.b2b.h3cw.com
http://lylgl.b2b.h3cw.com
http://hzcetrqz2.b2b.h3cw.com
http://heslzgzykt.b2b.h3cw.com
http://tybx2.b2b.h3cw.com
http://hzwhrqz2.b2b.h3cw.com
http://fsmdn2.b2b.h3cw.com
http://swdbgl2.b2b.h3cw.com
http://ydlalsdbgl.b2b.h3cw.com
http://hzbtrqz2.b2b.h3cw.com
http://hzghzjrqz2.b2b.h3cw.com
http://wlfgl4.b2b.h3cw.com
http://wbbx.b2b.h3cw.com
http://hzptrqz2.b2b.h3cw.com
http://wlfbgl5.b2b.h3cw.com
http://hzlbrqz2.b2b.h3cw.com
http://fsm2.b2b.h3cw.com
http://hzdyrqz2.b2b.h3cw.com
http://wsmrsq2.b2b.h3cw.com
http://wsmrsq.b2b.h3cw.com
http://hzhdrqz3.b2b.h3cw.com
http://hmtyn.b2b.h3cw.com
http://hzskyyj3.b2b.h3cw.com
http://hmtynrsq.b2b.h3cw.com
http://hzskrqz4.b2b.h3cw.com
http://smsbgl2.b2b.h3cw.com
http://hzsk4.b2b.h3cw.com
http://rmbgl.b2b.h3cw.com
http://yfnbgl.b2b.h3cw.com
http://hzskrqz3.b2b.h3cw.com
http://hzhr2.b2b.h3cw.com
http://xssbgl2.b2b.h3cw.com
http://hzhrmqz2.b2b.h3cw.com
http://hzhrzj2.b2b.h3cw.com
http://fllbgl3.b2b.h3cw.com
http://hzhrrql2.b2b.h3cw.com
http://hzhrrqz2.b2b.h3cw.com
http://rlxyj.b2b.h3cw.com
http://slzghezykt.b2b.h3cw.com
http://hzhwrqz2.b2b.h3cw.com
http://tyxyj.b2b.h3cw.com
http://xmzdbx.b2b.h3cw.com
http://alsdxyj.b2b.h3cw.com
http://mgty.b2b.h3cw.com
http://hzsjdrsq2.b2b.h3cw.com
http://aqhxyj.b2b.h3cw.com
http://ozzxbgl.b2b.h3cw.com
http://hzsjrsq2.b2b.h3cw.com
http://ddxyj.b2b.h3cw.com
http://hzkprqrsq2.b2b.h3cw.com
http://hzhrrsq2.b2b.h3cw.com
http://xmzbsbx.b2b.h3cw.com
http://hzhrrqrsq2.b2b.h3cw.com
http://bgl3.b2b.h3cw.com
http://mdbx.b2b.h3cw.com
http://hzqfrqrsq2.b2b.h3cw.com
http://bsrsq5.b2b.h3cw.com
http://alsdbgl4.b2b.h3cw.com
http://hzasddrsq2.b2b.h3cw.com
http://hzyhrqrsq2.b2b.h3cw.com
http://bxhbx.b2b.h3cw.com
http://hznlrsq6.b2b.h3cw.com
http://tybx.b2b.h3cw.com
http://hzyhrsq2.b2b.h3cw.com
http://sldjkt2.b2b.h3cw.com
http://hzsxxyj4.b2b.h3cw.com
http://hzsxxyj3.b2b.h3cw.com
http://hzhexyj2.b2b.h3cw.com
http://hzyxrsq2.b2b.h3cw.com
http://gdlmrsq.b2b.h3cw.com
http://hzxmzxyj4.b2b.h3cw.com
http://bsdn5.b2b.h3cw.com
http://hzxmzrqz2.b2b.h3cw.com
http://wmbgl.b2b.h3cw.com
http://hgyyj.b2b.h3cw.com
http://hzxmzbx4.b2b.h3cw.com
http://blm3.b2b.h3cw.com
http://hzxmzbx3.b2b.h3cw.com
http://hgrsq.b2b.h3cw.com
http://hzxmzxyj3.b2b.h3cw.com
http://hzxmzrsq4.b2b.h3cw.com
http://wndn2.b2b.h3cw.com
http://hzhwrsq2.b2b.h3cw.com
http://whyyj.b2b.h3cw.com
http://blmrsq3.b2b.h3cw.com
http://blm2.b2b.h3cw.com
http://fdorqz2.b2b.h3cw.com
http://hzcetrsq2.b2b.h3cw.com
http://rsdq.b2b.h3cw.com
http://hzqfrsq2.b2b.h3cw.com
http://xdrbgl6.b2b.h3cw.com
http://hzbsxyj3.b2b.h3cw.com
http://smbgl4.b2b.h3cw.com
http://jsrqz.b2b.h3cw.com
http://dds2.b2b.h3cw.com
http://hzbsbx3.b2b.h3cw.com
http://bltbgl7.b2b.h3cw.com
http://hzbsrsq4.b2b.h3cw.com
http://hzbs2.b2b.h3cw.com
http://mdrqz.b2b.h3cw.com
http://mdjcz2.b2b.h3cw.com
http://hzbsrsq3.b2b.h3cw.com
http://zgrqz.b2b.h3cw.com
http://blmrsdq.b2b.h3cw.com
http://hzalsdrsq2.b2b.h3cw.com
http://jftjcz.b2b.h3cw.com
http://hzlnrsq4.b2b.h3cw.com
http://gl3.b2b.h3cw.com
http://qtrsq2.b2b.h3cw.com
http://hzlnrsq3.b2b.h3cw.com
http://akdbgl3.b2b.h3cw.com
http://hgrqz.b2b.h3cw.com
http://hzkprsq2.b2b.h3cw.com
http://bltbgl6.b2b.h3cw.com
http://bgl2.b2b.h3cw.com
http://lbpyyj.b2b.h3cw.com
http://bxrsq.b2b.h3cw.com
http://spebgl.b2b.h3cw.com
http://lbdq.b2b.h3cw.com
http://hzhdrsq2.b2b.h3cw.com
http://hzslzgkt2.b2b.h3cw.com
http://bsgl3.b2b.h3cw.com
http://wngl4.b2b.h3cw.com
http://hzsldjkt2.b2b.h3cw.com
http://bxgl2.b2b.h3cw.com
http://dyxdg.b2b.h3cw.com