/**
* java字符串操作
* @author wydream
*
*/
public class StringTest {
public static void main(String[] args) {
String str="abCdeFg";
//1.length():统计字符串长度
System.out.println(str.length());
//2.indexOf:查找指定字符再字符串中的位置
System.out.println(str.indexOf("b"));
//3.toUpperCase:小写转大写
System.out.println(str.toUpperCase());
//4.toLowerCase:大写转小写
System.out.println(str.toLowerCase());
//5.substring:截取字符串
System.out.println(str.substring(0,3));
System.out.println(str.substring(3));
//6.replaceAll:替换当前字符串中指定的内容
str.replaceAll("ab", "xy");
System.out.println(str);
//7.trim:去掉当前字符串中两端的空格
str=" adeg efe efe ";
System.out.println(str.trim());
//8.+:字符串拼接
String str1="I LOVE ";
String str2="YOU";
System.out.println(str1+str2);
//9 将字符串变为整数
String str3="123";
int num=Integer.parseInt(str3);
System.out.println(num);
}
}
Java——字符串操作
未经允许不得转载:搜云库技术团队 » Java——字符串操作