String

String s1 = new String("abc");

String s2 = new String("abc");

boolean b = s1 == s2;  /* 结果返回false */

boolean b = s1.equals(s2);  /* 结果返回true */

String s3 = "abc";

String s4 = "abc";

boolean b = s3 == s4;  /* 此时结果返回true */

 

boolean b = "".isEmpty();  /* 判断字符串是否为空 */

char c = "abc".charAt(2);  /* 返回指定下标2的字符c */

int i = "abcbd".indexOf('b');  /* 返回对应字符的下标,从左往右的第一个指定字符。若不存在指定的字符,则返回-1 */

int i = "abcbd".lastIndexOf('b');  /* 返回对应字符的下标,从右往左的第一个指定字符。若不存在指定的字符,则返回-1 */

String s = "abc".substring(1);  /* 从指定下标1开始截取字符串直到最后 */

String s = "abc".replace('a', '*');  /* 将字符串的'a'字符全部用新字符'*'取代 */

String s = " aa bb ".trim();  /* 去除字符串的首尾空格,中间的空格不去除 */

boolean b = "ABc".equalsIgnoreCase("abc");  /* 忽略字母大小写进行比较 */

boolean b = "abcdef".startsWith("ab");  /* 判断字符串是否以指定字符串开头 */

boolean b = "abcdef".startsWith("ee");  /* 判断字符串是否以指定字符串结尾 */

String s = "AbegS".toLowerCase();  /* 将字符串中的大写字母全部变成小写 */

String s = "AbegS".toUpperCase();  /* 将字符串中的小写字母全部变成大写 */

 

String s = "abc,de,fghi";
String[] arr = s.split(",");  /* 将字符串以","为分界进行切割,返回一个字符串数组 */
for (String a : arr) {
  System.out.println(a);  /* 打印3个字符串"abc", "de", "fghi" */
}

posted on 2018-05-02 00:01  15767140984  阅读(97)  评论(0)    收藏  举报