String class
- The string class is a final class that represents the immutable string sequence
- The string is immutable, and once the string is in decibels, its contents are immutable.
The object equality in the string is "=", and the content is equal to "equals ()";
StringS1= "TTF";StringS2= "Java";StringS3= "Java";StringS4= New String("Java");StringS5= "Ttfjava"; System.Out.println (S2==S3);//true, all stored in a string constant poolSystem.Out.println (S2==S4);//false,s4 is an object, S2 is notSystem.Out.println (S2.equals(S4));//true, the comparison is the contentStringS6=(S1+S2).Intern ();//intern () is to put the object into a string constant poolSystem.Out.println (S5.equals(S6));//true, judging the time contentSystem.Out.println (S5==S6);//true, judging by the address, the same place
String"a""b";//把原来的s对象丢弃,产生一个新的ab;
Common methods
str.length();//字符串长度str.charAt(2);//字符串第三个字符str.trim();//去掉字符串两头的空白字符str.split(‘|‘);按照什么字符拆分字符串int num = parseInt(str);//将str转为基本数据类型
StringBuffer
- The StringBuffer class is a variable sequence of characters that can be used to delete the contents of a string
- The StringBuffer class is a container
- Method is the same as String
Construction method
StringBuffer()//初始一个容量为16的字符串缓冲区StringBuffer(int size);//构造指定容量的字符串缓冲区StringBuffer(String str)//将内容初始化为指定字符串内容
new StringBuffer("ttf");sb.append("love java");//给字符串缓冲区后面添加字符串
Append can add integers or object types
StringBuilder
- String Immutable character sequence
- StringBuffer variable character sequences, low efficiency, thread safety
- StringBuilder variable sequence of characters, high efficiency, thread insecure
StringBuilder usage is the same as StringBuffer.
Java-Common class String class, StringBuffer class, StringBuilder class