package cn.tedu.api;
import java.util.Arrays;
public class Test3_String { public static void main(String[] args) { char[] c = new char[]{'a', 'b', 'c', 'd', 'e'}; String s = new String(c); String s1 = s + 'F'; String s2 = ' ' + s + 'F' + ' '; System.out.println(s); System.out.println(s.charAt(3));//返回指定索引的字符 System.out.println(s.concat("fgh"));//在s后拼接fgh字符串不保存输出,拼接后s仍为abcde System.out.println(s);//abcde System.out.println(s.contains("bc"));//包含bc则输出true System.out.println(s.endsWith("de"));//判断是否以de结束 System.out.println(s.equals("abcde"));//判断是否相等 System.out.println(s.hashCode());//输出哈希码 System.out.println(s.indexOf("c"));//返回指定子字符串在此字符串中第一次出现处的索引。 System.out.println(s.indexOf("bcd")); System.out.println(s.indexOf("bcf"));//不存在返回 -1 System.out.println(s.isEmpty());//判断是否为空 System.out.println(s.length());//字符串长度 System.out.println(c.length);//数组长度 System.out.println(s.lastIndexOf("de"));//返回指定子字符串在此字符串中第一次出现处的索引。---3 System.out.println(s.lastIndexOf('e'));//返回指定字符在此字符串中第一次出现处的索引。 System.out.println(s.lastIndexOf('e', 2));//返回在此字符串中第一次出现指定字符处的索引,从指定的索引开始搜索。 System.out.println(s.startsWith("ab"));//测试此字符串是否以指定的前缀开始 System.out.println(s1.toLowerCase());//使用默认语言环境的规则将此 String 中的所有字符都转换为小写 System.out.println(s1.toUpperCase());//使用默认语言环境的规则将此 String 中的所有字符都转换为大写。 System.out.println(s1.substring(1));//返回一个新的字符串,它是此字符串的一个子字符串。从下标1开始 System.out.println(s1.substring(0, 4));//返回一个新的字符串,它是此字符串的一个子字符串。从下标1到下标(4-1)=3,---bcd System.out.println(s2); System.out.println(s2.trim());// 返回字符串的副本,忽略前导空白和尾部空白 char[] s0 = s2.toCharArray(); System.out.println(Arrays.toString(s0)); System.out.println(s0.length);//前后多了空格长度为8 System.out.println(s0[0]);//将此字符串转换为一个新的字符数组。空格 System.out.println(s0[1]);//将此字符串转换为一个新的字符数组。a System.out.println(s0[6]);//将此字符串转换为一个新的字符数组。F System.out.println(s0[7]);//将此字符串转换为一个新的字符数组。空格 String str = String.valueOf(10.2);//把10转换成String类型 System.out.println(str + 1);//10.21 byte[] b = s.getBytes();//String 编码为 byte 序列,并将结果存储到一个新的 byte 数组中。 System.out.println(Arrays.toString(b)); String s5 = "ab1cd1ef1xy1ddsa1gd1rb1"; String[] s4 = s5.split("1");//根据给定正则表达式的匹配拆分此字符串 System.out.println(Arrays.toString(s4));//[ab, cd, ef, xy, ddsa, gd, rb]
} }