复习Java之String API

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/github_34402358/article/details/88259890

Java 中的String类包含了50多个方法。摘抄之java核心技术卷一

  1. char charAt(int index)
    返回给定位置的代码单元。除非对底层的代码单元感兴趣,否则不需要调用这个方法。
  2. int codePointAt(int index)
    返回从指定位置开始的码点。
  3. int offsetByCodePoints(int startIndex,int cpCount)
    返回从startIndex代码点开始,位移cpCount后的码点索引。
  4. int compareTo(String other)
    按照字典顺序,如果字符串位于other之前,返回一个负数;如果字符串位于other之后,返回一个正数;如果两个字符串相等,返回0.
  5. IntStream codePoints()
    将这个字符串的码点当作一个流返回。调用toArray将它们放在一个数组中。
  6. new String(int[] codePoints,int oddest, int count)
    用数组中从offset开始的count哥码点构造一个字符串。
  7. boolean equals(Object other)
    如果字符串与other相等,返回true。
  8. boolean equalsIgnoreCase(String other)
    如果字符串与other相等(忽略大小写),返回true。
  9. boolean startWith(String prefix)
  10. boolean endWith(String suffix)
    如果字符串以suffix开头或者结尾,则返回true。
  11. int indexOf(String str)
  12. int indexOf(String str, int fromIndex)
  13. int indexOf(int cp)
  14. int indexOf(int cp, int fromIndex)
    返回与字符串str或代码点cp匹配的第一个子串的开始位置。这个位置从索引0或者fromIndex开始计算。如果在原始串中不存在str,返回-1。
  15. int lastIndexOf(String str)
  16. int lastIndexOf(String str, int fromIndex)
  17. int lastIndexOf(int cp)
  18. int lastIndexOf(int cp, int fromIndex)
    返回与字符串str或代码点cp匹配的最后一个子串的开始位置。这个位置从原始串尾端或fromIndex开始计算。
  19. int length()
    返回字符串长度。
  20. int codePointCount(int startIndex,int endIndex)
    返回startIndex和endIndex-1之间的代码点数量。没有配成对的代用字符串将计入代码点。
  21. String replace(CharSequence oldString,CharSequence newString)
    返回一个新字符串,这个字符串用newString替换字符串中所有oldString。
  22. String substring(int beginIndex)
  23. String substring(int beginIndex,int endIndex)
    返回一个新字符串,截取beginIndex位置到endIndex位置之间的字符串。
  24. String toLowerCase()
  25. String toUpperCase()
    返回一个新字符串,这个字符串将原始字符串的大写字母改为小写,或者将原始字符串的小写字母改为大写。
  26. String trim()
    返回一个新字符串,这个字符串删除原始字符串头部和尾部空格。
  27. String join(CharSequence delimiter,CharSequence… elements )
    返回一个新字符串,用给定的定界符连接所有元素。

猜你喜欢

转载自blog.csdn.net/github_34402358/article/details/88259890
今日推荐