StringBuffer
- StringBuilder:内容可以改变的Unicode字符序列,任何的修改都不会产生新对象,内部的数据变化,效率高
- 是一个可以保存字符的容器,底层仍然使用数组
- StringBuffer是线程安全的,效率低
- StringBuilder是线程不安全的,效率高
StringBuffer.append(String s),
StringBuffer append(int n) ,
StringBuffer append(Object o) ,
StringBuffer append(char n),
StringBuffer append(long n),
StringBuffer append(boolean n),
append()//在字符串末尾添加任意数据
StringBuffer insert(int index, String str) //在指定下标位置插入任意数据
public StringBuffer reverse() //反转字符串
StringBuffer delete(int startIndex, int endIndex(不包含)) //删除从start到end的字符
public char charAt(int n )//获取指定位置的字符
public void setCharAt(int n ,char ch) 替换指定下标的字符为新字符
StringBuffer replace( int startIndex ,int endIndex, String str)
public int indexOf(String str)//参数中的子串在原字符串中第一次出现的位置
public String substring(int start,int end)
public int length()
String
*//字符串:内容不可改变的Unicode字符的序列,任何的对字符串的修改都一定会产生新的字符串!!
//底层使用了char[]数组来保存字符,字符串的处理和下标密切相关
//字符串的字面量存在于常量区中
* 0 2 12 17 23 29 37 39
* String string = " abcABXXyy 我喜欢你,你喜欢我吗?我不喜欢你 qqyyZZ123 ";
*
* *****public int length() 获取字符串长度(字符数) string.length() => 40
*****public char charAt(int index) 获取参数指定的下标位置处的字符
public char[] toCharArray() 还原成字符数组,是一个新的数组对象,原字符串不变
System.arraycopy(源数组, 原数组开始的下标, 目标数组, 目标数组开始的小标, 复制的元素个数); 实现数组的复制
*****public boolean equals(Object anObject) 比较内容
public int compareTo(String anotherString) 比较大小
***public int indexOf(String s) 获取参数s这一子串在当前字符串中【首次】出现的位置, 用于检索。string.indexOf("喜欢") => 13,如果搜索失败,返回-1
**public int indexOf(String s ,int startpoint) 获取从startpoint位置开始子串在当前串的出现位置。
比如:获取【第2个】喜欢出现的位置:string.indexOf("喜欢", 14) => 18
public int lastIndexOf(String s) 从右向左搜索...string.indexOf("喜欢") => 25
public int lastIndexOf(String s ,int startpoint) 从右向左搜索... string.indexOf("喜欢", 24); => 18
**public boolean startsWith(String prefix) 判断字符串是否以参数中的子串为开始 string.startsWith(" abc") => true
**public boolean endsWith(String suffix) 判断字符串是否以参数中的子串结束 string.endsWith("123") => false
*****public String substring(int start,int end) 从当前字符串中截取子串,开始下标,结束下标(不包含)
public String substring(int startpoint) 从当前下标开始取子串
public String replace(char oldChar,char newChar) 替换字符串中所有旧字符为新字符,以字符为单位替换
public String replaceAll(String old,String new) 全部替换老串为新串,以字符串为单位替换,特殊字符\ [ * + 要小心
public String trim() 修剪字符串的首尾的空白字符(码值小于等于32的字符是空白字符,就是不可见字符)
public String concat(String str) 和+一样
public String toUpperCase()改变大小写,变大写
public String toLowerCase()变小写
public String[] split(String regex)以参数中的子串为切割器,把字符串切割成多个部分