方法:
1、构造:public String(byte[] bytes)
public String(byte [] bytes,int offset,int length) 从offset索引处开始,将长度为length的字节数组转换为字符串
2、普通:public byte[] getBytes()public byte[] getBytes(String charsetName)throws UnsupportedEbcodingException(编码操作)
字符串和字符
1、构造:public String(char[] value)
public String(char []value,int offset,int count)
2、普通:char chraAt(int index)返回索引值处的值char [] toCharArray()字符串转换为字符数组
字符串比较
1、public boolean equals()区分大小写
2、public boolean equalsIgnoreCase()不区分大小写
3、public int compareTo()编码比较
返回值大于0 :大于
小于0:小于
等于0: 等于
字符串查找
1、public boolean contains(String str);重要
2、public int indexOf(String str);从前往后查找没有返回-1,有返回第一个字母索引值
3、public int indexOf(String str,int fromIndex);
4、public int lastIndexOf(String str,int prefix);从后往前
5、boolean startsWith(String str);
6、boolean startsWith(String str,int offset);从确定索引处判断是否以此开头7、boolean endsWith(String suffix)结尾
字符串替换
1、String replaceFirst(String regex, String replacement) 替换首个regex(正则表达式)
2、String replaceAll(String regex, String replacement) 替换全部regex
字符串截取
1、String substring(int beginIndex) 从指定位置截取到结尾
2、 String substring(int beginIndex, int endIndex) 从指定位置截取到指定位置
字符串拆分
1、String [] split(String regex,int limit)按照指定的字符串拆分程不大于limit的字符串数组
2、String [] split(String regex)按照指定的字符串全部拆分
其他方法
1、String concat(String str)和+运算一样
2、public String toLowerCase(String str);将字符串转换成小写
3、public String toUpperCase(String str);转换成大写
3、String trim(String str);去掉字符串两边的空格
4、public String length(); 返回字符串的长度(注意和数组的length属性区分)
5、Stirng interm()数据如池
6、boolean isEmpty();判断字符串是否为“”(不是null)