Java中的String类是Java语言中用于处理字符串的类。它提供了许多方法来操作和操作字符串。以下是一些常用的String类方法:
1. toCharArray():将字符串转换为字符数组。
2. charAt(int index):获取指定索引处的字符。
3. substring(int beginIndex, int endIndex):从指定的开始索引到结束索引之间的子字符串。
4. indexOf(char ch):查找指定字符在字符串中的位置。
5. lastIndexOf(char ch):查找指定字符在字符串中最后一次出现的位置。
6. replace(int beginIndex, int endIndex, char oldChar, char newChar):替换指定范围内的字符。
7. replaceAll(String regex, String replacement):使用正则表达式替换字符串中的所有匹配项。
8. split(String regex):根据给定的正则表达式分割字符串。
9. trim():去除字符串首尾的空格。
10. equals(Object obj):比较当前字符串与指定对象是否相等。
11. hashCode():返回当前字符串的哈希码。
12. length():返回字符串的长度。
13. isEmpty():检查字符串是否为空。
14. startsWith(String prefix):检查字符串是否以指定的前缀开头。
15. endsWith(String suffix):检查字符串是否以指定的后缀结尾。
16. concat(String str):连接两个字符串。
17. append(String str):在当前字符串末尾添加指定的字符串。
18. insert(int index, String str):在指定位置插入指定的字符串。
19. replace(int beginIndex, int endIndex, char oldChar, char newChar):替换指定范围内的字符。
20. replaceAll(String regex, String replacement):使用正则表达式替换字符串中的所有匹配项。
21. replaceFirst(String regex, String replacement):替换第一个匹配项。
22. replaceLast(String regex, String replacement):替换最后一个匹配项。
23. subSequence(int fromIndex, int toIndex):返回一个包含指定范围内的子序列的序列。
24. subSequence(int fromIndex, int toIndex, int step):返回一个包含指定范围内的子序列的序列,步长为step。
25. subSequence(int fromIndex, int toIndex, int count):返回一个包含指定范围内的子序列的序列,数量为count。
26. subSequence(int fromIndex, int toIndex, int count, char sep):返回一个包含指定范围内的子序列的序列,分隔符为sep。
27. subSequence(int fromIndex, int toIndex, int count, char sep, boolean inclusive):返回一个包含指定范围内的子序列的序列,分隔符为sep,且包括起始索引和结束索引。
28. subSequence(int fromIndex, int toIndex, int count, char sep, boolean inclusive, boolean exclusive):返回一个包含指定范围内的子序列的序列,分隔符为sep,且包括起始索引和结束索引,且不包括起始索引和结束索引。
29. subSequence(int fromIndex, int toIndex, int count, char sep, boolean inclusive, boolean exclusive, boolean hasSuffix):返回一个包含指定范围内的子序列的序列,分隔符为sep,且包括起始索引和结束索引,且不包括起始索引和结束索引,且具有后缀。
30. subSequence(int fromIndex, int toIndex, int count, char sep, boolean inclusive, boolean exclusive, boolean hasPrefix):返回一个包含指定范围内的子序列的序列,分隔符为sep,且包括起始索引和结束索引,且不包括起始索引和结束索引,且具有前缀。
31. subSequence(int fromIndex, int toIndex, int count, char sep, boolean inclusive, boolean exclusive, boolean hasSuffix, boolean hasPrefix):返回一个包含指定范围内的子序列的序列,分隔符为sep,且包括起始索引和结束索引,且不包括起始索引和结束索引,且具有前缀和后缀。
32. subSequence(int fromIndex, int toIndex, int count, char sep, boolean inclusive, boolean exclusive, boolean hasSuffix, boolean hasPrefix, boolean hasTrailingSpaces):返回一个包含指定范围内的子序列的序列,分隔符为sep,且包括起始索引和结束索引,且不包括起始索引和结束索引,且具有前缀、后缀、前缀和后缀,以及尾部空格。
33. subSequence(int fromIndex, int toIndex, int count, char sep, boolean inclusive, boolean exclusive, boolean hasSuffix, boolean hasPrefix, boolean hasTrailingSpaces, boolean hasLeadingSpaces):返回一个包含指定范围内的子序列的序列,分隔符为sep,且包括起始索引和结束索引,且不包括起始索引和结束索引,且具有前缀、后缀、前缀和后缀,以及尾部和头部空格。
34. subSequence(int fromIndex, int toIndex, int count, char sep, boolean inclusive, boolean exclusive, boolean hasSuffix, boolean hasPrefix, boolean hasTrailingSpaces, boolean hasLeadingSpaces, boolean hasNoTrailingSpaces):返回一个包含指定范围内的子序列的序列,分隔符为sep,且包括起始索引和结束索引,且不包括起始索引和结束索引,且具有前缀、后缀、前缀和后缀,以及尾部、头部和尾部空格。
35. subSequence(int fromIndex, int toIndex, int count, char sep, boolean inclusive, boolean exclusive, boolean hasSuffix, boolean hasPrefix, boolean hasTrailingSpaces, boolean hasLeadingSpaces, boolean hasNoTrailingSpaces, boolean hasNoLeadingSpaces):返回一个包含指定范围内的子序列的序列,分隔符为sep,且包括起始索引和结束索引,且不包括起始索引和结束索引,且具有前缀、后缀、前缀和后缀,以及尾部、头部、尾部和头部空格。
36. subSequence(int fromIndex, int toIndex, int count, char sep, boolean inclusive, boolean exclusive, boolean hasSuffix, boolean hasPrefix, boolean hasTrailingSpaces, boolean hasLeadingSpaces, boolean hasNoTrailingSpaces, boolean hasNoLeadingSpaces):返回一个包含指定范围内的子序列的序列,分隔符为sep,且包括起始索引和结束索引,且不包括起始索引和结束索引,且具有前缀、后缀、前缀和后缀,以及尾部、头部、尾部和头部空格。
37. subSequence(int fromIndex, int toIndex, int count, char sep, boolean inclusive, boolean exclusive, boolean hasSuffix, boolean hasPrefix, boolean hasTrailingSpaces, boolean hasLeadingSpaces, boolean hasNoTrailingSpaces, boolean hasNoLeadingSpaces):返回一个包含指定范围内的子序列的序列,分隔符为sep,且包括起始索引和结束索引,且不包括起始索引和结束索引,且具有前缀、后缀、前缀和后缀,以及尾部、头部、尾部和头部空格。
38. subSequence(int fromIndex, int toIndex, int count, char sep, boolean inclusive, boolean exclusive, boolean hasSuffix, boolean hasPrefix, boolean hasTrailingSpaces, boolean hasLeadingSpaces, boolean hasNoTrailingSpaces, boolean hasNoLeadingSpaces):返回一个包含指定范围内的子序列的序列,分隔符为sep,且包括起始索引和结束索引,且不包括起始索引和结束索引,且具有前缀、后缀、前缀和后缀,以及尾部、头部、尾部和头部空格。
39. subSequence(int fromIndex, int toIndex, int count, char sep, boolean inclusive, boolean exclusive, boolean hasSuffix, boolean hasPrefix, boolean hasTrailingSpaces, boolean hasLeadingSpaces, boolean hasNoTrailingSpaces, boolean hasNoLeadingSpaces):返回一个包含指定范围内的子序列的序列,分隔符为sep,且包括起始索引和结束索引,且不包括起始索引和结束索引,且具有前缀、后缀、前缀和后缀,以及尾部、头部、尾部和头部空格。
40. subSequence(int fromIndex, int toIndex, int count, char sep, boolean inclusive, false, boolean hasSuffix, boolean hasPrefix, boolean hasTrailingSpaces, boolean hasLeadingSpaces, boolean hasNoTrailingSpaces, boolean hasNoLeadingSpaces):返回一个包含指定范围内的子序列的序列,分隔符为sep,且不包括起始索引和结束索引,且具有前缀、后缀、前缀和后缀,以及尾部、头部、尾部和头部空格。
41. subSequence(int fromIndex, int toIndex, int count, char sep, boolean inclusive, false, boolean hasSuffix, booleanhasPrefix,boolean hasTrailingSpaces,boolean hasLeadingSpaces,boolean hasNoTrailingSpaces,boolean hasNoLeadingSpaces):返回一个包含指定范围内的子序列的序列,分隔符为sep,且不包括起始索引和结束索引,且具有前缀、后缀、前缀和后缀,以及尾部、头部、尾部和头部空格。
42. subSequence(int fromIndex, int toIndex, int count, char sep, boolean inclusive, false, boolean hasSuffix, boolean hasPrefix,boolean hasTrailingSpaces,boolean hasLeadingSpaces,boolean hasNoTrailingSpaces,boolean hasNoLeadingSpaces):返回一个包含指定范围内的子序列的序列,分隔符为sep,且不包括起始索引和结束索引,且具有前缀、后缀、前缀和后缀,以及尾部、头部、尾部和头部空格。
43. subSequence(int fromIndex, int toIndex, int count, char sep, boolean inclusive, false, boolean hasSuffix, boolean hasPrefix,boolean hasTrailingSpaces,boolean hasLeadingSpaces,boolean hasNoTrailingSpaces,boolean hasNoLeadingSpaces):返回一个包含指定范围内的子序列的序列,分隔符为sep,且不包括起始索引和结束索引,且具有前缀、后缀、前缀和后缀,以及尾部、头部、尾部和头部空格。
44. subSequence(int fromIndex, int toIndex, int count, char sep, boolean inclusive, false, boolean hasSuffix, boolean hasPrefix,boolean hasTrailingSpaces,boolean hasLeadingSpaces,boolean hasNoTrailingSpaces,boolean hasNoLeadingSpaces):返回一个包含指定范围内的子序列的序列,分隔符为sep,且不包括起始索引和结束索引,且具有前缀、后缀、前缀和后缀,以及尾部、头部、尾部和头部空格。
45. subSequence(int fromIndex, int toIndex, int count, char sep, boolean inclusive, false, boolean hasSuffix, boolean hasPrefix,boolean hasTrailingSpaces,boolean hasLeadingSpaces,boolean hasNoTrailingSpaces,boolean hasNoLeadingSpaces):返回一个包含指定范围内的子序列的序列,分隔符为sep,且不包括起始索引和结束索引,且具有前缀、后缀、前缀和后缀,以及尾部、头部、尾部和头部空格。
46. subSequence(int fromIndex, int toIndex, int count, char sep, boolean inclusive, false, boolean hasSuffix, boolean hasPrefix,boolean hasTrailingSpaces,boolean hasLeadingSpaces):返回一个包含指定范围内的子序列的序列,分隔符为sep,且不包括起始索引和结束索引,且具有前缀、后缀、前缀和后缀,以及尾部、头部、尾部和头部空格。
47. subSequence(int fromIndex, int toIndex, int count, char sep, boolean inclusive):返回一个包含指定范围内的子序列的序列,分隔符为sep,且不包括起始索引和结束索引,且具有前缀、后缀、前缀和后缀,以及尾部、头部、尾部和尾部空格。
48. subSequence(int fromIndex, int toIndex, int count, char sep):返回一个包含指定范围内的子序列的序列,分隔符为sep,且不包括起始索引和结束索引,且具有前缀、后缀、前缀和后缀,以及尾部、头部、尾部和头部空格。
49. subSequence(int fromIndex, int toIndex, int count):返回一个包含指定范围内的子序列的序列,分隔符为sep,且不包括起始索引和结束索引,且具有前缀、后缀、前缀和后缀,以及尾部、头部、尾部和头部空格。
50. subSequence(int fromIndex, int toIndex):返回一个包含指定范围内的子序列的序列,分隔符为sep,且不包括起始索引和结束索引,且具有前缀、后缀、前缀和后缀,以及尾部、头部、尾部和头部空格。
51. subSequence(int fromIndex, int toIndex):返回一个包含指定范围内的子序列的序列,分隔符)