String中常用的方法
时间: 2024-05-27 11:10:59 浏览: 17
1. length():返回字符串的长度。
2. charAt(int index):返回字符串中指定位置的字符。
3. substring(int beginIndex):返回从指定位置开始到字符串末尾的子字符串。
4. substring(int beginIndex, int endIndex):返回指定位置范围内的子字符串。
5. indexOf(char ch):返回指定字符在字符串中第一次出现的位置。
6. indexOf(String str):返回指定字符串在字符串中第一次出现的位置。
7. lastIndexOf(char ch):返回指定字符在字符串中最后一次出现的位置。
8. lastIndexOf(String str):返回指定字符串在字符串中最后一次出现的位置。
9. equals(Object obj):比较字符串与指定对象是否相等。
10. equalsIgnoreCase(String str):比较字符串与指定字符串是否相等,不区分大小写。
11. toUpperCase():将字符串转换为大写。
12. toLowerCase():将字符串转换为小写。
13. trim():返回去除首尾空格的字符串。
14. replace(char oldChar, char newChar):将字符串中指定字符替换为新字符。
15. replace(CharSequence target, CharSequence replacement):将字符串中指定字符序列替换为新字符序列。
相关问题
java中string类常用方法
Java中String类是一个非常常用的类,它提供了许多方法来处理和操作字符串。以下是一些常用的String类方法:
1. length():获取字符串的长度。
2. charAt(int index):获取字符串中指定位置的字符。
3. substring(int beginIndex, int endIndex):获取字符串中指定范围内的子串。
4. indexOf(String str):查找字符串中指定子串的位置。
5. lastIndexOf(String str):查找字符串中指定子串最后出现的位置。
6. equals(Object anObject):比较字符串是否相等。
7. toUpperCase():将字符串转换为大写。
8. toLowerCase():将字符串转换为小写。
9. trim():去除字符串两端的空格。
这些方法只是String类提供的众多方法中的一部分,它们在字符串处理和操作中非常有用。通过熟练掌握这些方法,您可以更好地处理和操作字符串。
java中string的常用方法
Java中String的常用方法包括:
1. length():返回字符串的长度。
2. charAt(int index):返回指定索引处的字符。
3. substring(int beginIndex, int endIndex):返回从beginIndex开始到endIndex-1的子字符串。
4. equals(Object anObject):比较字符串是否相等。
5. toUpperCase():将字符串转换为大写。
6. toLowerCase():将字符串转换为小写。
7. indexOf(String str):返回指定字符串在该字符串中第一次出现的索引。
8. replace(char oldChar, char newChar):用新字符替换字符串中的旧字符。
9. trim():去除字符串两端的空格。
10. split(String regex):根据给定的正则表达式拆分字符串。
以上是Java中String的常用方法。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)