String x="abcDbcD ";
System.out.println(x.charAt(1));//查找第x个字符
System.out.println(x.length());//返回长度
System.out.println(x.indexOf('b'));//返回第一次出现的b的下标
System.out.println(x.indexOf("cd",4));//获取从下标4开始查找,出现“”的第一个字符下标
System.out.println(x.lastIndexOf("cD"));//获取从字符串后面算起的字符位置
System.out.println(x.endsWith("d"));//判断是否以“”结尾
System.out.println(x.startsWith("a"));//判断是否以“”开头
System.out.println(x.contains("cdc"));//判断是否包含"cdc"
System.out.println(x.toCharArray());//字符串转化成字符数组
char y[]={'a','b','c','d'};
//String str=new String(y);
System.out.println(new String(y));//字符数组转化成字符串
System.out.println(x.equals(new String(y)));//判断x,y是否相等
double z=1234.56;
System.out.println(String.valueOf(z));//数字转字符串
System.out.println(x.replace("bc","ttttt"));//用后一个字符串替换前一个
String[] num=x.split("b");//以‘b’为分割线,将x字符串分割成三部分
for(int i=0;i<num.length;i++)
if(i!=num.length-1)
System.out.print(num[i]+" ");
else
System.out.println();
System.out.println(x.substring(3));//输出下标从..开始的剩余子串
System.out.println(x.substring(2,x.length()));//输出从。。到。。的子串
System.out.println(x.toUpperCase());//将字符串转化成大写
System.out.println(x.toLowerCase());//将字符串转化成小写
System.out.println(x.trim());//将字符串两端的空格去掉
System.out.println(x.compareTo(new String(y))); |
|