Packing class:
Wrapper class with relative data type:
BYTE---Byte
Short---short
int---Integer
Long---long
Float---float
Double---double
Boolean---Boolean
Char---Character
Why should I have a packing type?
wrapper classes convert basic type data to Objects : Because Java is an object-oriented language, the basic type does not have the nature of the object, and in order to "conform" to other objects there is a wrapper type (such as when we use the collection type collection, we must use the wrapper type rather than the base type), it is equivalent to the basic type "Wrapping up" makes it have the nature of the object, and adds properties and methods to it, enriching the operation of the basic type.
The role of the wrapper class : 1. Provides a series of practical methods
2. The collection is not allowed to hold the basic data type data, when storing the number, to use the packing type
The integer class describes the actual use of the wrapper class as an example:
1. Implement conversions between int and integer classes
// in the actual conversion, using the integer class construction method and the internal Intvalue method of the integer class to achieve the conversion between these types, the implementation of the code is as follows: int n = ten; New Integer (+); // converting an int type to an integer type New Integer (n); // convert an object of type integer to an int type int m = In.intvalue ();
Common methods within the 2.Integer class
parseint Method: Converts a numeric string to an int value.
String s = "123"; int n = integer.parseint (s);
public static int parseint (string s, int radix): Converts the string to an int by the input specified by the parameter radix.
// converts the string "120" to int by decimal, the result is int n = integer.parseint ("+", "ten"); // converts the string "12" to int according to the 16 binary, the result is int n = integer.parseint ("a", +); // converts the string "FF" to int according to 16, the result is 255 int n = integer.parseint ("FF", 16);
ToString Method: Converts the int type to the corresponding string type
int m = integer.tostring (m); // The value of the string s is "1000".
public static int parseint (string s, int radix): Converts the int value to a specific binary string
int m =; = integer.tostring (m,2); System.out.println (s); // The result of converting 20z to binary is 10100
JDK since 1.5 (version, the introduction of the Automatic Disassembly box syntax, that is, the basic data type and the corresponding wrapper class conversion, the system will automatically.
int m =N; = m; // the integer type is automatically converted to type int int n = in;
// Digital Processing class // maximum minimum value for each data type System.out.println (integer.min_value); System.out.println (integer.max_value); System.out.println (byte.min_value); System.out.println (byte.max_value); System.out.println (long.min_value); System.out.println (long.max_value); System.out.println (short.min_value); System.out.println (short.max_value); System.out.println (float.min_value); System.out.println (float.max_value); System.out.println (double.min_value); System.out.println (double.max_value);
For the wrapper class, the use of these classes consists of two main types:
A, as the basic data type corresponding to the class type exists, convenient to involve the operation of the object.
b, contains the relevant attributes for each basic data type, such as maximum, minimum, and related methods of operation.
Similarities and differences between package types and basic types
1. In different ways, the base type does not apply the new keyword, and the wrapper type needs to use the New keyword to allocate storage space in the heap;
2. Different storage methods and locations, the basic type is to store the value of the variable directly on the stack, and the wrapper type is to put the object in the heap, and then by reference to use;
3. Different initial values, the initial value of the base type, such as int is 0,boolean to false, and the initial value of the wrapper type is null
4. The use of different methods, the basic type of direct assignment directly to use, and the package type in the collection, such as collection, map will be used to
Other:
Declares an array:
int ints[] = new INT[3];
New represents a newly opened area in memory
Analysis of Java Digital processing class