xxxValue() from primitive wrappers takes no arguments, returns a primitive
parseXxx() from primitive wrappers takes a String, returns a primitive
valueOf() from primitive wrappers takes a String, returns a wrapped object
Wrapper constructors can take a String or a primitive, except for Character, which can only take a char.
Radix refers to bases (typically) other than 10; octal is radix = 8, hex = 16.
Boxing allows you to convert primitives to wrappers or to convert wrappers to primitives automatically.
public class MainClass {
public static void main(String args[]) {
Boolean b1 = new Boolean("TRUE");
Boolean b2 = new Boolean("FALSE");
System.out.println(b1.toString()+" or "+b2.toString());
for(int j=0;j<16;++j){
System.out.print(Character.forDigit(j,16));
}
Integer i = new Integer(Integer.parseInt("ef",16));
Long l = new Long(Long.parseLong("abcd",16));
long m=l.longValue()*i.longValue();
System.out.println(Long.toString(m,8));
System.out.println(Float.MIN_VALUE);
System.out.println(Double.MAX_VALUE);
}
}
true or false
0123456789abcdef50062143
1.4E-45
1.7976931348623157E308
8.9.Wrapper classes |
| 8.9.1. | Wrapper classes |
| 8.9.2. | Wrapper classes and their corresponding primitive variables. |
| 8.9.3. | Each Java primitive data type has a corresponding wrapper class. |
| 8.9.4. | The Wrapper Constructors |
| 8.9.5. | The Character class provides only one constructor, which takes a char as an argument |
| 8.9.6. | The constructors for the Boolean wrapper take either a boolean value true or false, or a String. |
| 8.9.7. | The valueOf() Methods |
| 8.9.8. | Using Wrapper Conversion Utilities |
| 8.9.9. | parseXxx() and valueOf() |
| 8.9.10. | toString() |
| 8.9.11. | Integer and Long provide a toString() method based on a radix. |
| 8.9.12. | toXxxString() (Binar y, Hexadecimal, Octal) |
| 8.9.13. | autoboxing, auto-unboxing, boxing, and unboxing. |
| 8.9.14. | Assignment to wrapper object |
| 8.9.15. | Each of the primitive data types has a corresponding wrapper class in the Java standard library. |
| 8.9.16. | Integer.parseInt(): convert int to string |
| 8.9.17. | Integer.valueOf(String s) returns Integer objects |
| 8.9.18. | Integer.MAX_VALUE is the largest value and Integer.MIN_VALUE the smallest that an int primitive can contain. |
| 8.9.19. | Wrapper classes can be constructed by passing the value to the appropriate constructor. |
| 8.9.20. | Pass into the constructor a String that represents the value to be wrapped. |
| 8.9.21. | The values wrapped inside two wrappers of the same type can be checked for equality |
| 8.9.22. | After a value has been wrapped, you may eventually need to extract it. |
| 8.9.23. | Sometime you need wrapper class |
| 8.9.24. | Useful methods from wrapper class |
| 8.9.25. | All wrapper classes except Character have a static method called valueOf(String s) |
| 8.9.26. | static wrapper methods parseXXX() |
| 8.9.27. | Boolean.getBoolean(), Integer.getInteger(), and Long.getLong(). |
| 8.9.28. | All the wrapper classes provide toString() methods. |
| 8.9.29. | Integer and Long classes provide toBinaryString(), toOctalString(), and toHexString() methods |
| 8.9.30. | The values All wrapper classes wrap are immutable and Wrapper classes are final. |