Java string Parsing

Source: Internet
Author: User

Java's virtual machines create a separate area in memory that is used to store string objects, a memory area called a string buffer pool.
When creating a string, look for objects that do not have the same object in the string buffer pool, if the same object returns a reference to the object directly
If you do not have the same object, create the object in the string, and then return the object's reference
String a = "123";
String B = "123";

= = Compares memory addresses for equality
if (a = = b) {
SYSTEM.OUT.PRINTLN ("Output equal");
}else{
System.out.println ("unequal");
}
Two objects created
One is the object created in the 567 buffer pool
One is the object created in the object memory of new, but the address that C points to is in memory
String d = "567";
String c = new String ("567");
if (d = = c) {
System.out.println ("D and C equal");
}else{
SYSTEM.OUT.PRINTLN ("Output D and C are not equal");
}
if (D.equals (c)) {
System.out.println ("Output EQUALSD and C equal");
}else{
System.out.println ("EQUALSD and C are not equal");
}
Returns a reference to a string object in the buffer pool
c = C.intern ();
if (d = = c) {
SYSTEM.OUT.PRINTLN ("Output D and C equal");
}else{
System.out.println ("D and C are not equal");
}

String a1 = "Dogapple";
String A2 = "Dog";
String a3 = "Apple";
String A4 = a2 + A3;
SYSTEM.OUT.PRINTLN (a1 = = A4);
System.out.println (A1.equals (A2+A3));

Java string Parsing

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.