String构造器
new String() -无参构造
new String(byte[] bytes) -根据参数 字节数组 创建字符串对象(默认utf-8)
new String(byte[] bytes, int offset, int length)-根据参数 字节数组的指定下标以及长度 创建字符串对象(默认utf-8)
new String(byte[] bytes, String charsetName) -通过使用指定的charset,解码指定的 byte 数组,构造一个新的String
new String(char[] value) -根据参数 字符数组 创建字符串对象
new String(char[] value, int offset, int count) -根据参数 字符数组的指定下标以及长度 创建字符串对象
String方法
.length() -返回字符串中的字符个数
.getBytes() -转成byte数组返回(默认utf-8字符编码格式)
.getBytes(String charsetName) -转成byte数组返回(指定编码格式)
.charAt(int index) -返回指定索引处的char值
.codePointAt(int index) -返回指定索引处的字符(Unicode 代码点)
.compareTo(String anotherString) -比较字典中的数字差返回
.compareToIgnoreCase(String str) -比较字典中的数字差返回(忽略大小写)
.concat(String str) -将指定字符串连接到此字符串的结尾
.contains(CharSequence s) -当且仅当此字符串包含指定的char值,返回true
String.copyValueOf(char[] data) -返回指定数组中表示该字符序列的 String。
String.copyValueOf(char[] data, int offset, int count) -返回指定数组中表示该字符序列的 String。
String.valueOf(Object obj) -返回 Object 参数的字符串表示形式
.endsWith(String suffix) -测试此字符串是否以指定的后缀结束。
.startsWith(String prefix) -测试此字符串是否以指定的前缀开始。
.getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) -将字符从此字符串复制到目标字符数组
.indexOf(String str) -返回指定子字符串在此字符串中第一次出现处的索引
.int indexOf(String str, int fromIndex) -返回指定子字符串从指定下标开始,在此字符串中第一次出现处的索引
.replace(char oldChar, char newChar) -替换字符
.split(String regex) -根据指定字符串分割成一个字符串数组
.substring(int beginIndex) -返回一个从指定下标开始的新的字符串,它是此字符串的一个子字符串
.substring(int beginIndex, int endIndex) -返回一个从指定下标开始到指定下标结束(不包含)的新字符串,它是此字符串的一个子字符串
.toCharArray() -将此字符串转换为一个新的字符数组
.toLowerCase() -转小写
.toUpperCase() -转小写
.trim() -去首尾空格
String类的构造器以及方法
最新推荐文章于 2024-05-10 23:21:21 发布