(1)用 equals检测两个字符串是否相等,如 s.equals(t) ; 用 == 进行相等性测试的话,类似于指针,只能够确定两个字符串是否放在同一个位置上。
(2)常用methods
- char charAt(int index) 返回给定位置的代码单元
- boolean equals(Object other)字符串相等,返回true
- boolean equalsIgnoreCase(Object other)字符串相等(忽略大小写),返回true
- boolean contains (CharSequence s) 当且仅当此字符串包含指定的char值序列时才返回true。 相比startsWith【比较是否有指定的前缀】和endsWith【是否有指定的后缀】更通用。
- static String valueOf (char[] data) 字符数组转字符串
- int length ( ) 返回此字符串的长度
- String[] split(String regex) 将此字符串分割。
String A = "you are not alone";
String[] temp = A.split(" ");//temp = ["you","are","not","alone"]
- char[] toCharArray( ) 将此字符串转换为字符数组。
- String substring(int beginIndex, int endIndex) 返回一个字符串,该字符串是此字符串的子字符串。 包含beginIndex,不包含endIndex。
(0,str.length()) 为完整字符串