Packaging box-packing and unpacking-in-process conversion

Source: Internet
Author: User


Introduction

Basic data type Object wrapper class

byte byte
Short Short
int IntegerInteger.max_value
Long Long
Float Float
Double Double
Char Character
Boolean Boolean

Auto boxing, automatic unpacking
  
    Integer i = 4; //Auto-boxing, automatically converted to the following form: integer i = new integer (4);  i + = 6; //auto-unpacking int, then automatically boxed to integer  System.out.println (i); //10. Note that I is still an integer, equivalent to System.out.println (i.ToString ()); 

is equal
   System.out.println (new integer) = = new integer (128)); //false System.out.println (new integer (127) = = new integer (127)); //false System.out.println ("*****************************************");
Integer c1 = 128; //equivalent to Integer c1 =new integer (+); Integer c2 = n;System.out.println (C1 = = C2); //false Integer d1 = 127;Integer d2 = 127;System.out.println (D1 = = D2); //true, if the auto-boxed is "one byte", then the object will be shared and will not be recreated System.out.println ("*****************************************");int e1 = 127; Integer e2 = 127;System.out.println (e1 = = E2); //true System.out.println (e1 = = new Integer (127)); //true System.out.println (e2 = = new Integer (127)); //false

basic types and strings are swapped with each other
   //Basic Type---> stringSYSTEM.OUT.PRINTLN (123 + 1 + ""); //124 System.out.println ("" + 123 + 1); //1231 System.out.println (integer.tostring (123) + 1); //1231 System.out.println (string.valueof (123) + 1); //1231 System.out.println ("******************************************");//String---> Basic typeSystem.out.println (new Integer (123) + 1); //124, first automatic unpacking, after automatic packing System.out.println (new Integer ("123") + 1); //124 System.out.println (Integer.parseint ("123") + 1); //124 System.out.println (new Integer ("123"). Intvalue ()); //123 System.out.println (new Integer (123). Intvalue ()); //123 

Binary Conversion
   //Decimal ---Other binarySystem.out.println (integer.tobinarystring (16)); //2, 10000 System.out.println (integer.tooctalstring (16)); //8 system, System.out.println (integer.tohexstring (16)); //16 System, ten System.out.println (Integer.tostring (16, 2)); //Can be converted to any binary , 10000System.out.println ("*******************************************");//A binary string--and decimal numberSystem.out.println (Integer.parseint (" -06")); //-6, converts a decimal string to a decimal number System.out.println (Integer.parseint (" -10", 2)); //-2, converting a binary string to a decimal number System.out.println (Integer.parseint (" -10", 16)); //-16, converts a 16 binary string to a decimal number 



From for notes (Wiz)

Packaging box-packing and unpacking-in-process conversion

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.