String类里都有什么方法
时间: 2024-05-26 19:10:15 浏览: 14
String类中常用的方法有:charAt、codePointAt、codePointBefore、codePointCount、compareTo、concat、contains、endsWith、equals、equalsIgnoreCase、format、getBytes、hashCode、indexOf、isEmpty、lastIndexOf、length、matches、regionMatches、replace、replaceAll、replaceFirst、split、startsWith、subSequence、substring、toCharArray、toLowerCase、toString、toUpperCase、trim。
相关问题
string 类的常用方法都有那些?
常用的 string 类方法有:
- len():返回字符串长度
- strip():移除字符串两侧的空格
- split():按照指定字符将字符串分割成多个子串
- replace():替换字符串中的某些字符
- upper() / lower():将字符串转换为大写/小写
- find() / index():查找子串在字符串中的位置
- startswith() / endswith():判断字符串是否以某个子串开始/结尾
- join():将多个字符串连接成一个字符串
- count():统计子串在字符串中出现的次数
- format():格式化字符串
需要注意的是这只是一部分常用方法,string类还有更多方法可以使用.
String类有几个构造方法
String类有十几个构造方法,其中常用的包括:
1. `String()`:创建一个空字符串。
2. `String(char[] value)`:使用字符数组创建一个字符串。
3. `String(byte[] bytes)`:使用字节数组创建一个字符串,按照平台的默认字符集转换为字符。
4. `String(byte[] bytes, Charset charset)`:使用字节数组和指定的字符集创建一个字符串。
5. `String(char[] value, int offset, int count)`:使用字符数组中的一部分创建一个字符串。
6. `String(int[] codePoints, int offset, int count)`:使用指定的Unicode代码点数组中的一部分创建一个字符串。
等等。
相关推荐
![](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)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)