String s ="zxcvbnm";//7个字母 System.out.println(s.length());//执行结果:7获取特定位置的字符 char charAt(int index);
String s ="zxcvbnm"; System.out.println(s.charAt(4));//执行结果为:b获取特定字符的下标 int indexOf(String str);
String s ="zxcvbnm";
System.out.println(s.indexOf("m"));//执行结果为:6
获取最后一个字符位置 int lastlndexOf(int ch);
String s ="zxcvbnm";
System.out.println(s.lastIndexOf('m'));
返回值是布尔类型的数据
boolean endWith(String str); 是否以指定的字符或者子字符串结尾
String a ="aqwert";
System.out.println(a.endsWith("t"));//true
System.out.println(a.endsWith("r"));//false
boolean isEmpty();判断是否为空
String a ="aqwert";
System.out.println("a".isEmpty());//true
System.out.println("".isEmpty());//false
boolean conatins(String str); 是否包含子字符串
System.out.println("zxc".contains("z"));//true
System.out.println("zxc".contains("a"));//false
boolean equals(object obj); 判断字符串内容是否相等
System.out.println("abc".equals("ABc"));//false
boolean equalsIgnoreCase();忽略大小写 判断两个字符串是否相等System.out.println("abc".equalsIgnoreCase("ABc"));//true
将字符数组转为字符串直接使用String类的构造方法
new String (char[] chs);char[] chs = {'中', '午', '吃', '黄', '焖', '鸡'};
String str1 = new String(chs);
System.out.println(str1);//执行结果为:中午吃黄焖鸡
char[] chs = {'中', '午', '吃', '黄', '焖', '鸡'};
String str3 = String.valueOf(chs);
System.out.println(str3);//执行结果为:中午吃黄焖鸡
String b1 = String.valueOf(true);
System.out.println(b1);//true
String i1 = String.valueOf(12);
System.out.println(i1);//12
String d1 = String.valueOf(12.4589494949494949499);
System.out.println(d1);//12.4589494949494949499
//字符串转数组
//八大基本数据类型的数组打印的都是十六进制内存地址 除了char数组
char[] arr = "abcd".toCharArray();
System.out.println(arr);//abcd
int[] arr1 = {1,2,4};
System.out.println(arr1);//内存地址
System.out.println("abcdef".replace('c', '人'));//ab人def
String replaceAll(String regex, String original);字符串在字符串中的替换System.out.println("天天向上".replace('上', '下'));//天天向下
String[] split(String regex); 以regex来进行字符串的切割String subString(int beginIndex); 截取字符串的一部分
System.out.println("abcdef".substring(2));//要头不要尾,执行结果为:cdef
String subString(int beginIndex, int endIndex); 截取字符串的一部分System.out.println("abcdef".substring(2,4));//cd
String toUpperCase();将小写字母转换为大写字母System.out.println("abCD".toUpperCase());//ABCD
String toLowerCase();将大写转为小写字母
System.out.println("ABFRgh".toLowerCase());//abfrgh
String trim();去除字符串中首尾的空格
System.out.println(" abcd fgh ".trim());//abcd dgh



