java.lang.string常用API

来源:互联网 发布:攻城狮和程序员打油诗 编辑:程序博客网 时间:2024/05/29 04:54
  1. char charAt(int index)
    返回给定位置的代码单元

  2. int codePointAt(int index)
    返回从给定位置开始的码点

  3. String[] split(String regex)
    根据给定正则表达式的匹配拆分此字符串

  4. int offsetByCodePoints(int startIndex, int cpCount)
    返回从startIndex代码点开始, 位移cpCount后的码点索引

  5. int compareTo(String other)
    按照字典顺序,如果字符串位于other之前,返回负数,之后,返回正数,字符串相等,返回0

  6. IntStream codePoints()
    将这个字符串的码点作为一个流返回。调用toArray将它们放在一个数组中

  7. new String(int[] coudePoints, int offset, int count)
    用数组中从offset开始的count个码点构造一个字符串

  8. boolean equals(Object other)
    如果字符串与other相等,返回true

  9. boolean equalsIgnoreCase(String other)
    如果字符串与other相等(忽略大小写),返回true

  10. boolean startsWith(String prefix)
    boolean endsWith(String suffix)
    如果字符串以suffix开头或结尾,则返回true

  11. int indexOf(String str)
    int indexOf(String str, int fromIndex)
    int indexOf(int cp)
    int indexOf(int cp, int fromIndex)
    返回与字符串str或代码点cp匹配的第一个子串的开始位置。这个位置从
    索引0或fromIndex开始计算。如果在原始串中不存在str,返回-1

  12. int lastIndexOf(String str)
    int lastIndexOf(String str, int fromIndex)
    int lastIndexOf(int cp)
    int lastIndexOf(int cp, int fromIndex)
    返回与字符串str或代码点cp匹配的最后一个子串的开始位置。这个位置
    从原始串尾端或fromIndex开始计算

  13. int length()
    返回字符串长度

  14. int codePointCount(int startIndex, int endIndex)
    返回startIndex和endIndex-1之间的代码点数量。没有配成对
    的代用字符将计入代码点

  15. String replace(CharSequence oldString, CharSequence newString)
    返回一个新字符串。这个字符串用newString代替原始字符串中所有的oldString。
    可以用String或StringBuilder对象作为CharSequence参数。

  16. String substring(int beginIndex)
    String substring(int beginIndex, int endIndex)
    返回一个新字符串。这个字符串包含原始字符串中从beginIndex到串尾或endIndex–1的所有代码单元。

15.String toLowerCase( )
String toUpperCase( )
返回一个新字符串。这个字符串将原始字符串中的所有大写字母改成了小写字母,或小写字母改成了大写字母。

String trim( )
返回一个新字符串。这个字符串将删除了原始字符串头部和尾部的空格。

原创粉丝点击