//String类方法 //http://www.chuanke.com/v4242218-139425-449283.html?st=1280 public class TestMethod{ public static void main(String args[]){ String s = "Hello World"; //返回字符串下标为n的字符 System.out.println("s.charAt:"+s.charAt(1)); char [] cs=s.toCharArray();//转化为字符数组 System.out.println(cs);//Hello World! System.out.println("------String方法------"); //字符串长度 System.out.println("s.length:"+s.length()); //截取,返回s字符串中下标0到4的子字符串 System.out.println("s.substring:"+s.substring(0,5)); //返回子字符串"Hello"的下标 System.out.println("s.indexOf:"+s.indexOf("Hello")); //将s转换为大写字母 System.out.println("s.toUpperCase:"+s.toUpperCase()); // 将s转换为小写 System.out.println("s.toLowerCase:"+s.toLowerCase()); //替换操作 System.out.println("s.replace:"+s.replace("World","xiaodeng")); //以某字符串开头或结尾 System.out.println("s.startsWith:"+s.startsWith("Hel"));//true System.out.println("当前字符串s为:"+s); System.out.println("s.endsWith:"+s.endsWith("World"));//可用于判断文件后缀名 //分割split String y="xiaodeng FengMei"; String [] values=y.split(" "); for (int i=0;i<values.length;i++){ System.out.println(values[i]); } } }