First, the concept
The advantage of encapsulating a basic data type as an object is that more functional methods can be defined in the object to manipulate the data.
Second, common Operation 1. Common operation:
Used for conversions between the base data type and the string.
Basic data types |
Packing class |
Byte |
Byte |
Short |
Short |
Int |
Integer |
Long |
Long |
Float |
Float |
Double |
Double |
Char |
Character |
Boolean |
Boolean |
2.Object object parent of all objects
Object to basic data type conversions need to be directly converted through wrapper class string and base data type must also be done through wrapper class
Iii. Common Application Scenario 3.1 numeric values of the base type are converted to strings (string type)
There are two ways: a). Basic data type + "", B). String.valueof (basic data type)
int A = ten= a + "" = string.valueof (a);
3.2String types of strings converted to basic data types
Wrapper classes that use basic data types
String STR3 = "n"; int i = integer.parseint (STR3); double d = double.parsedouble (STR3);
Conversions between 3.3 and binary
A) decimal conversion to other binary
// decimal conversion into binary System.out.println (integer.tobinarystring (30)); // 11110, // decimal into octal System.out.println (integer.tohexstring (30)); // 1e // convert decimal to hexadecimal System.out.println (integer.tooctalstring (30)); // $
b) other conversions into decimal
System.out.println (Integer.parseint ("11110", 2)); // -
3.4 Conversion of basic data types and wrapper classes
A). basic data type converted to wrapper class
New Integerin2= integer.valueof (30);
b). The wrapper class is converted into a basic data type
// jdk1.7 cannot be converted directly between int a = in.intvalue (); // jdk1.7 can then be converted by itself . int b = in;
Wrapper classes for basic data type objects