First, Basic Data Type wrapper class
- The reference data type is typically capitalized on the base data type, except for int, char, where the reference data type of the int class Integer,char is character
- Relationship:
Relationships between basic data types are compatible with each other
There is no relationship between the wrapper class for the base data type
3. Conversion between the basic data type and the basic data type wrapper class
3.1 Boxing: Encapsulates a basic data type into a corresponding wrapper class type
Grammar:
jdk>1.5 Automatic packing
A reference to the wrapper type Object = Basic data type;
static Integer valueOf (int i) is called by default
jdk<1.5 Manual Boxing
Reference to wrapper type Object = new wrapper type (base data type)
3.2 Unpacking: Splitting the wrapper type into a basic data type
Grammar:
jdk>=1.5 Automatic Unpacking
Basic data type variable name = object of wrapper class;
the int intvalue () method is called by default to complete
jdk<1.5 Manual Unboxing
Basic data type variable name = a reference to the wrapper class's object. Intvalue ();
Second, conversion issues between strings and base data types
- Convert String to int
First: Integer (String s) using integer construction method
Integer in = new Integer (s); Required to be a number in a string
int c = In.intvalue (); Unpacking
Second type: static int parseint (string s) complete string to int using static method in integer class
int d = integer.parseint (s);
2.int Conversion to String
The first type: String s=e+ "";
Second type: integer in= new Integer (e);
String s2 = in2.tostring (); Convert integer to String type
The third type: String s3 = Integer.tostring (e);
Fourth type: String class static string valueOf (int i)
Precautions:
- Although the basic data type wrapper class is a reference data type, it passes the value itself when the method passes the parameter.
- = = The address value is always compared when comparing objects in Java A==integer b-->false
Basic data wrapper classes and simple conversions for Java Basics (11)