关于indexOf、 substring、split、contains的用法


public class StringTest{
protected StringTest(){
}
public static void main ( String[] args ){
String s = "Call me Accp.";
System.out.println( s + "的长度为:" + s.length());
System.out.println("字符串的第一个字符为:" + s.charAt(0));
System.out.println("字符串的最后一个字符为:" + s.charAt(s.length()-1));
System.out.println("字符串的C第一次出现的位置为:" + s.indexOf('c'));
System.out.println("字符串的的子串:" + s.substring(2));
}
}

/*
----------------------------------
Call me Accp.的长度为:13
字符串的第一个字符为:C
字符串的最后一个字符为:.
字符串的C第一次出现的位置为:9
字符串的的子串:ll me Accp.
------------------------------------

*/

点击打开链接

——————————————————————————————————————————————————

string 类型中的split是将字符串按照某个字符拆分成一个字符串数组,例如有这样一个字符串str="abcd;ert;yui" ,
使用string[] strs=str.split(';')则将获得一个三元素的字符串数组{abcd,ert,yui}

————————————————————————————————————————————

JAVA中的String.contains分大小写吗 

例如
String str="clear";
此时
boolean S=str.contains("c");和boolean S1=str.contains("C");两个变量的会值一样吗,也就是S和S1会都是true吗

答:contains()方法是确定给定字符的char值在本字符串中是否包含!
事实上“c”的char值跟“C”的char值是不一样的。。
—————————————————————————————————————————————

猜你喜欢

转载自blog.csdn.net/wangdd_199326/article/details/80774661