类 CharSequenceUtil

java.lang.Object
org.elsfs.tool.core.util.CharSequenceUtil

public class CharSequenceUtil extends Object
CharSequence 相关工具类封装
从以下版本开始:
0.0.3
作者:
zeng
  • 字段概要

    字段
    修饰符和类型
    字段
    说明
    static final String
    字符串常量:空字符串 ""
  • 构造器概要

    构造器
    构造器
    说明
     
  • 方法概要

    修饰符和类型
    方法
    说明
    static boolean
    字符串是否为空白,空白的定义如下: null 空字符串:"" 空格、全角空格、制表符、换行符,等不可见字符
    static boolean
    字符串是否为空,空的定义如下: null 空字符串:""
    static String
    CharSequence 转为字符串,null安全
    static String
    sub(CharSequence str, int fromIndexInclude, int toIndexExclude)
    改进JDK subString
    index从0开始计算,最后一个字符为-1
    如果from和to位置一样,返回 ""
    如果from或to为负数,则按照length从后向前数位置,如果绝对值大于字符串长度,则from归到0,to归到length
    如果经过修正的index中from大于to,则互换from和to example:
    abcdefgh 2 3 =》 c
    abcdefgh 2 -3 =》 cde
    static String
    subSuf(CharSequence string, int fromIndex)
    切割指定位置之后部分的字符串
    static String
    大写首字母
    例如:str = name, return Name

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 字段详细资料

    • EMPTY

      public static final String EMPTY
      字符串常量:空字符串 ""
      另请参阅:
  • 构造器详细资料

    • CharSequenceUtil

      public CharSequenceUtil()
  • 方法详细资料

    • isBlank

      public static boolean isBlank(CharSequence str)
      字符串是否为空白,空白的定义如下:
      1. null
      2. 空字符串:""
      3. 空格、全角空格、制表符、换行符,等不可见字符

      例:

      • StrUtil.isBlank(null) // true
      • StrUtil.isBlank("") // true
      • StrUtil.isBlank(" \t\n") // true
      • StrUtil.isBlank("abc") // false

      注意:该方法与 isEmpty(CharSequence) 的区别是: 该方法会校验空白字符,且性能相对于 isEmpty(CharSequence) 略慢。

      建议:

      • 该方法建议仅对于客户端(或第三方接口)传入的参数使用该方法。
      参数:
      str - 被检测的字符串
      返回:
      若为空白,则返回 true
      另请参阅:
    • isEmpty

      public static boolean isEmpty(CharSequence str)
      字符串是否为空,空的定义如下:
      1. null
      2. 空字符串:""

      例:

      • StrUtil.isEmpty(null) // true
      • StrUtil.isEmpty("") // true
      • StrUtil.isEmpty(" \t\n") // false
      • StrUtil.isEmpty("abc") // false

      注意:该方法与 isBlank(CharSequence) 的区别是:该方法不校验空白字符。

      建议:

      • 该方法建议用于工具类或任何可以预期的方法参数的校验中。
      参数:
      str - 被检测的字符串
      返回:
      是否为空
    • upperFirst

      public static String upperFirst(CharSequence str)
      大写首字母
      例如:str = name, return Name
      参数:
      str - 字符串
      返回:
      字符串
    • subSuf

      public static String subSuf(CharSequence string, int fromIndex)
      切割指定位置之后部分的字符串
      参数:
      string - 字符串
      fromIndex - 切割开始的位置(包括)
      返回:
      切割后后剩余的后半部分字符串
    • sub

      public static String sub(CharSequence str, int fromIndexInclude, int toIndexExclude)
      改进JDK subString
      index从0开始计算,最后一个字符为-1
      如果from和to位置一样,返回 ""
      如果from或to为负数,则按照length从后向前数位置,如果绝对值大于字符串长度,则from归到0,to归到length
      如果经过修正的index中from大于to,则互换from和to example:
      abcdefgh 2 3 =》 c
      abcdefgh 2 -3 =》 cde
      参数:
      str - String
      fromIndexInclude - 开始的index(包括)
      toIndexExclude - 结束的index(不包括)
      返回:
      字串
    • str

      public static String str(CharSequence cs)
      CharSequence 转为字符串,null安全
      参数:
      cs - CharSequence
      返回:
      字符串