- Boxing: Basic data type to wrapper class
- Unpacking: Wrapper class to basic data type
- jdk1.5 (i.e. jdk5.0) versions are available with auto-boxing and auto-unpacking capabilities
- Wrapper classes for basic data types
- For two examples, take a look at
1 Public classDemo01 {2 3 Public Static voidMain (string[] args) {4 5 6 7 inti = 3;//Basic data Types8Integer I1 =NewInteger (i);//Packing class packing9 System.out.println (i);Ten System.out.println (i1); One A - //Turn 100 of the string into a number -String s = "100"; the //String s = "abc"; Wrong, Java.lang.NumberFormatException . -Integer i2 =NewInteger (s); - System.out.println (i2); - + - inti3 = I1.intvalue ();//Unpacking + System.out.println (i3); A at - //S--> int - intI4 = Integer.parseint (s);//How to convert a string to a number - System.out.println (I4); - - in - //automatic boxing and unpacking after JDK 1.5 to intj = 5; + -Integer J1 = j;//Automatic Boxing//integer J3 = new Integer (j); the * intJ2 = J1;//Automatic Unpacking $ Panax Notoginseng - //print maximum and minimum values of type int the System.out.println (integer.max_value); + System.out.println (integer.min_value); A the + //Binary Conversion - //Decimal Turn hex $System.out.println (integer.tohexstring (1000)); $ //Decimal Turn octal -System.out.println (integer.tooctalstring (9)); - //Decimal Turn binary theSystem.out.println (Integer.tobinarystring (3)); - Wuyi the -Integer II1 =NewInteger (1234);//heap in-memory fetch WuInteger II2 = 1234;//go to the method area to find - intII3 = 1234;//II1 Unpacking int About $System.out.println (II1 = = Ii3);//T - - //Although the property values are the same, but the referenced addresses are different, "= =" compares the referenced addresses -System.out.println (II1==II2);//F A + //The equals method is overridden in the Integer class, compared to the property value theSystem.out.println (Ii1.equals (II2));//T - $ the //byte [ -128-127] the theByte B1 =-123; theByte B2 =-123; - inSystem.out.println (B1 = =B2); the System.out.println (B1.equals (B2)); the About the the}
1 Public classDemo02_character {2 3 Public Static voidMain (string[] args) {4 5System.out.println ((int) ' 1 ');6 7 CharC1 = ' A ';8 CharC2 = 49;9System.out.println ("C2 =" +C2);Ten OneCharacter C3 = C1;//Character C4 = new Character (c1); A -System.out.println (Character.isdigit (C1));//determines whether a character is a number F -System.out.println (Character.isletter (C1));//determines whether a character is a letter T theSystem.out.println (Character.islowercase (C1));//determine if the lowercase letter F -System.out.println (Character.isuppercase (C1));//determine if an uppercase T - -System.out.println (character.tolowercase (' C '));//uppercase to lowercase c +System.out.println (Character.touppercase (' a '));//lowercase to uppercase A - +}
- Similar to the use of byte/short/long/float/double and Integer (int) classes
java--Eight basic data types (common classes)