主要构造方法 String str = ""; String str = new String(); String str = new String("adf"); String str = new String(byte[] b); //char[] String str = new String(StringBuilder sb);//StringBuffer 常用方法 char charAt(int index) // 返回指定索引处的 char 值。 int compareTo(String anotherString)// 按字典顺序比较两个字符 //串。 int compareToIgnoreCase(String str) //按字典顺序比较两个字符 //串,不考虑大小写。 String concat(String str)// 将指定字符串连接到此字符串的结尾。 byte[] getBytes() /* 使用平台的默认字符集将此 String 编码为 byte 序列,并将结果存储到一个新的 byte 数组中。 */ byte[] getBytes(Charset charset) /* 使用给定的 charset 将此 String 编码到 byte 序列,并将结果存储到新的 byte 数组。 */ //同理还有lastIndexOf() int indexOf(int ch) //返回指定字符在此字符串中第一次出现处的索引。 int indexOf(int ch, int fromIndex) //返回在此字符串中第一次出现指定字符处的索引,从指定的索引开始搜索。 int indexOf(String str) // 返回指定子字符串在此字符串中第一次出现处的索引。 int indexOf(String str, int fromIndex) //返回指定子字符串在此字符串中第一次出现处的索引,从指定的索引开始。 boolean isEmpty() //当且仅当 length() 为 0 时返回 true。 int length() // 返回此字符串的长度。 String substring(int beginIndex) // 返回一个新的字符串,它是此字符串的一个子字符串。 String substring(int beginIndex, int endIndex) //返回一个新字符串,它是此字符串的一个子字符串。 char[] toCharArray() //将此字符串转换为一个新的字符数组。 String toLowerCase() // 使用默认语言环境的规则将此 String 中的所有字符都转换为小写。 String toUpperCase() // 使用默认语言环境的规则将此 String 中的所有字符都转换为大写。 String trim() // 返回字符串的副本,忽略前导空白和尾部空白。