字符串与字符数组:
public String(char[] value) //将字符数组中的所有内容变为字符串 String s = new String(Arrar);
public String(char[] value, int offset, int count) //将部分字符数组中的内容变为字符串。
public char charAt(int index) //取得索引位置的指定字符(索引从0开始)。
public char[] toCharArray() //将字符串变为字符数组。
字符串比较:
public boolean equals(Object anObject)
public int compareTo(String anotherString)
字符串查找:
public boolean contains(String s) //Returns true if and only if this string contains the specified sequence of char values.
public int indexOf(String str)
public int indexOf(String str, int fromIndex) //从指定位置开始查找并返回子字符串的位置。
public int lastIndexOf(String str) //由后向前查找某字符串位置。
public int lastindexOf(String str, int fromIndex)
public boolean startsWith(String prefix) //判断是否以指定字符串开头。
public boolean startsWith(String prefix, int toffset ) //从指定位置开始判断
public boolean endsWith(String suffix) //判断是否以指定字符串结尾。
字符串替换:
public String replace(CharSequence target, CharSequence replacement)
public String replaceAll(String regex, String replacement) //替换所有内容
public String replaceFirst(String regex, String replacement) //替换首个内容
字符串拆分:
public String[] split(String regex) //将字符串整个拆分。
public String[] split(String regex, int limit) //将字符串部分拆分。limit为拆分后的字符串数组最多个数。
有符号不能被直接拆分:如 . |等,此时需要在之前加上\\。例如str.split("\\.")。
字符串截取:
public String substring(int beginIndex) 从指定位置截取到结尾。
public String substring(int beginIndex, int endIndex) //从指定位置截取到指定位置。
字符串其它操作方法:
public String trim() //去除字符串左右的空格,保留中间空格。
public String toUpperCase() //字符串转大写。
public String toLowerCase() //字符串转小写。
int length()
public boolean isEmpty() //判断是否为空字符串,但不是null,是长度为0。