一. string的常用方法整理
String 是基于字符数组 char[] 实现的,String 实现了 Serializable 接口,所以支持序列化和反序列化支持
String常用方法
substring()
length() 返回字符串长度
isEmpty() 返回字符串是否为空
charAt(int index) 返回字符串中第(index+1)个字符(数组索引)
char[] toCharArray() 转化成字符数组
trim()去掉两端空格
toUpperCase()转化为大写
toLowerCase()转化为小写
String concat(String str) 拼接字符串
String replace(char oldChar, char newChar) 将字符串中的
boolean matches(String regex) 判断字符串是否匹配给定的regex正则表达式
boolean contains(CharSequence s) 判断字符串是否包含字符序列 s
String[] split(String regex, int limit) 按照字符 regex将字符串分成 limit 份
String[] split(String regex) 按照字符 regex 将字符串分段
比较方法
boolean equals(Object anObject); 比较对象
boolean contentEquals(String Buffersb); 与字符串比较内容
boolean contentEquals(Char Sequencecs); 与字符比较内容
boolean equalsIgnoreCase(String anotherString);忽略大小写比较字符串对象
int compareTo(String anotherString); 比较字符串
int compareToIgnoreCase(String str); 忽略大小写比较字符串
boolean regionMatches(int toffset, String other, int ooffset, int len)局部匹配
boolean regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len)
public native String intern(); 该方法返回一个字符串对象的内部化引用
string1.concat(string2) 字符串连接