String s = "HadoopJava12138";
遍历字符串,得到每一个字符
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
1、先获取第一个字符
// char c = s.charAt(0);
String s1 = s.substring(0,1);
2、再获取除了第一个以外的字符
String s2 = s.substring(1);
3、把第一步的字符转成大写
String s3 = s1.toUpperCase();
4、把第二部获取的字符转成小写
String s4 = s2.toLowerCase();
5、把第三步和第四步的字符串拼接
String result = s3.concat(s4);
String s = "helloworld";
//String replace(char old,char new)
//将字符串中所有的l替换成a,返回一个新的字符串
String s1=s.replace('l','a');
System.out.println(s1);
//String replace(String old,String new)
//将字符串中的字符串owo替换成wow,返回一个新的字符串
//如果被替换的字符串不存在,返回原来的字符串
String s2 =s.replace("owo","wow");
System.out.println(s2);
//String trim()
//去除字符串两边的空格,不能去除字符串中间的空格
String s1=s.trim();
System.out.println(s1);
//int compareTo(String str)
//按字典顺序比较两个字符串
String s2 = "hello"; //h的ASCLL码值:104
String s3 = "hello";
String s4 = "abc"; // a的ASCLL码值:97
String s5 = "qwe"; // q的ASCLL码值:113
System.out.println(s2.compareTo(s3)); // 0
System.out.println(s2.compareTo(s4)); // 7 104-97
System.out.println(s2.compareTo(s5)); // -9 104-113
// 如果前面的几个字符都是一样的怎么办呢?
String s = "hello";
String s3 = "hellobigdata";
String s2 = "hel";
System.out.println(s.compareTo(s2));//2
System.out.println(s3.compareTo(s));//7