************************************************************************* * * * Original:blog.csdn.net/clark_xu Xu Changliang's Column************************************************************************Basic type wrapper class
The 8 basic types of chalk for the Java language correspond to 8 wrapper classes, each of which encapsulates a corresponding basic type of member variable, and also provides some methods for using positive-to-correct data types
Java.lang.Interger |
Int |
Java.lang.Long |
Long |
Java.lang.Double |
Double |
Java.lang.Character |
Char |
Java.lang.Boolean |
Boolean |
Java.lang.Byte |
Byte |
Java.lang.Float |
Float |
Java.lang.Short |
Short |
3.1Compiler support for wrapper classes
before JDK 5 was released, the tedious " unboxing " and " boxing" operations were required when using wrapper class objects for operations
Packing
Interger i=integer.valueof (100);
Interger j=integer.valueof (200);
Unpacking + Boxing:
Integer k=interger.valueof (I.intvalue () + j.intvalue ());
JDK 5 adds automatic unpacking and boxing features, including
interger i=100;interger j=200;
Interger K=i+j;
3.2 IntegerAndDoubleCommon Methods for objects
The static constants of Integer and Double max_value and min_value are used to return
The parseint and parsedouble methods can parse the string into int and double data, respectively, and if the data string cannot be resolved to a numeric value will be thrown NumberFormatException, for example:
int N=integer. parseint ("123");
Double d=double.parsedouble ("123.456");
Integer tobinarystring and tohexstring methods convert int data to binary and hexadecimal string sequences, respectively
String bstr=integer.tobinarystring (100);
String hstr=integer.tohexstring (100);
3.3 BigDecimalClass
The floating data type of java float,double The rounding error when the operation is being computed, and if you want to get the exact result, use the Java.math.BigDecimal class
Use the constructor method of the String parameter, for example:
BigDecimal d1=new BigDecimal ("3.0");
BigDecimal object has subtract,add,multiply,divide method, which corresponds to divide method, specifies precision, prevents invalid decimal exception
BigDecimal d4=d1.divide (D2,8,BIGDECIMAL.ROUND_HALF_UP);
3.4 BigIntegerClass
Use BigInteger 's static method ValueOf to build the object, the number of arguments long type.
Created as:BigInteger sum=biginteger.valueof (1)
The number of bits obtained is:sum.toString.length ();
"Javase" Basic type wrapper class