127 critical point of Java Basic Data Type Packing, 127 critical point of Packing

Source: Internet
Author: User

127 critical point of Java Basic Data Type Packing, 127 critical point of Packing

1 package wrapper. demo; 2 3 public class WrapperDemo 4 {5 6/** 7 * @ param args 8 */9 public static void main (String [] args) 10 {11 12 // automatically boxed after JDK1.5. If one byte is packed, the data will be shared and no new space will be reopened 13 Integer a = 127; 14 Integer B = 127; 15 System. out. println (a = B); // true16 System. out. println (. equals (B); // true17 18 Integer c = 128; 19 Integer d = 128; 20 System. out. println (c = d); // false 21 System. out. println (c. equals (d); // true22 23 Integer x = new Integer (127); 24 Integer y = new Integer (127); 25 System. out. println (x = y); // false, because = is the object address, two new, obviously the address is not the same 26 System. out. println (x. equals (y); // true, override the equals method, only compare whether the values are equal, obviously equal 27 28} 29 30}

 

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.