zoukankan      html  css  js  c++  java
  • Apache Commons--StringUtils字符串操作

    需要包:commons-lang.jar

    StringUtils是字符串工具类,主要方法如下:

      1、public static boolean isEmpty(CharSequence cs):判断字符串是否为“”或者null,    

        StringUtils.isEmpty(null) = true
        StringUtils.isEmpty("") = true
        StringUtils.isEmpty(" ") = false
        StringUtils.isEmpty("bob") = false
        StringUtils.isEmpty(" bob ") = false

      2、public static boolean isNotEmpty(CharSequence cs):判断字符串是否不为“”或者不为null

        StringUtils.isNotEmpty(null) = false
        StringUtils.isNotEmpty("") = false
        StringUtils.isNotEmpty(" ") = true
        StringUtils.isNotEmpty("bob") = true
        StringUtils.isNotEmpty(" bob ") = true

      3、public static boolean isAnyEmpty(CharSequence... css):任意一个参数为空的话,返回true,如果这些参数都不为空的话返回false 

        StringUtils.isAnyEmpty(null) = true
        StringUtils.isAnyEmpty(null, "foo") = true
        StringUtils.isAnyEmpty("", "bar") = true
        StringUtils.isAnyEmpty("bob", "") = true
        StringUtils.isAnyEmpty(" bob ", null) = true
        StringUtils.isAnyEmpty(" ", "bar") = false
        StringUtils.isAnyEmpty("foo", "bar") = false

      4、public static boolean isNoneEmpty(CharSequence... css):任意一个参数是空,返回false,所有参数都不为空,返回true   

        StringUtils.isNoneEmpty(null) = false
        StringUtils.isNoneEmpty(null, "foo") = false
        StringUtils.isNoneEmpty("", "bar") = false
        StringUtils.isNoneEmpty("bob", "") = false
        StringUtils.isNoneEmpty(" bob ", null) = false
        StringUtils.isNoneEmpty(" ", "bar") = true
        StringUtils.isNoneEmpty("foo", "bar") = true

      5、public static boolean isBlank(CharSequence cs):判断字符对象是不是空字符串   

        StringUtils.isBlank(null) = true
        StringUtils.isBlank("") = true
        StringUtils.isBlank(" ") = true
        StringUtils.isBlank("bob") = false
        StringUtils.isBlank(" bob ") = false

      6、public static boolean isNotBlank(CharSequence cs):判断字符对象是不是不为空字符串

      7、public static boolean isAnyBlank(CharSequence... css):判断字符串是不是空字符串,都是空字符串就返回true,否则返回false

      8、public static boolean isNoneBlank(CharSequence... css):判断字符串是不是不是空字符串,全部不是空字符串就返回true,否则返回false 

      9、public static String trim(String str):去除字符串首尾的空格

      10、public static boolean equals(CharSequence cs1, CharSequence cs2):判断字符串是否相等

      11、public static boolean equalsIgnoreCase(CharSequence str1, CharSequence str2):字符串比较,忽略大小写

      12、public static int indexOf(CharSequence seq, int searchChar):返回字符串首次出现的位置索引

      13、public static int ordinalIndexOf(CharSequence str, CharSequence searchStr, int ordinal):判断字符串在另一个字符串第几次出现的位置索引

      14、public static int lastIndexOf(CharSequence seq,int searchChar):字符在字符串中最后一次出现的位置索引

      15、public static int lastOrdinalIndexOf(CharSequence str,CharSequence searchStr, int ordinal):判断字符在字符串倒数第几次出现的位置索引

      16、public static boolean contains(CharSequence seq, int searchChar):判断是字符是否在另一个字符串中

      17、public static String substring(String str,int start):字符串截取

      18、public static String left(String str,int len):字符串左边的多少个字符

        public static String right(String str, int len):字符串右边的多少个字符

        

      

  • 相关阅读:
    Linux 进程学习(四) sigaction 函数
    Netty 编解码奥秘
    我的博客即将同步至 OSCHINA 社区,这是我的 OSCHINA ID:护国小将,邀请大家一同入驻:https://www.oschina.net/sharingplan/apply
    Netty数据如何在 pipeline 中流动
    PLM系统安装四:主卷服务安装(FSC缓存服务器plm4IP:42.20)
    Linux系统信息和进程相关命令(CPU,内存,进程)
    SAN交换机配置的备份还原,固件升级
    san交换机的级联
    PLM系统安装五(2):Corporate服务安装plm1IP:42.106
    第三步:服务器虚拟化XenServer实施部署文档
  • 原文地址:https://www.cnblogs.com/-scl/p/7679241.html
Copyright © 2011-2022 走看看