"Java-Common Class" String class, StringBuffer class, StringBuilder class

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.