11String类

String s1 = "abcd";          

String s2 = new String("ab cd");

//System.out.println(s1 == s2);

 

返回索引为1的值,空格也算

char c=s1.charAt(1);

System.out.println(c);

 

是否包含

System.out.println(s1.contains("b"));

 

是否是xxx结尾

System.out.println(s1.endsWith("c"));

 

s变成byte数组

byte [] b=s1.getBytes();

for (byte d : b) {

System.out.println(d);

}

 

拼接

System.out.println(s1.concat("aaaaaa"));

 

返回指定字符在s出现的第一次位置

System.out.println(s1.indexOf(98));

System.out.println(s1.indexOf("c"));

//s1.intern();

 

System.out.println("---------------------");

 

返回指定字符在此字符串中最后一次出现处的索引。

System.out.println(s1.lastIndexOf("a"));

 

长度

System.out.println(s1.length());

 

替换

System.out.println(s1.replace("a", "b"));

 

 

 

分组,分类

String[] arr=s2.split(" ");

for (String bb : arr) {

System.out.println(bb);

}

 

是否是xx开头

System.out.println(s1.startsWith("aa"));

 

截取

System.out.println(s1.substring(2));

 

字符串变数组

char ccc[]= s1.toCharArray();

for (char d : ccc) {

System.out.println(d);

}

 

变大写

System.out.println(s1.toUpperCase());

 

转成String

System.out.println(String.valueOf(false));

posted @ 2019-11-27 16:47  北儿陌丫~  阅读(99)  评论(0)    收藏  举报