toXxxString() (Binar y, Hexadecimal, Octal) : Wrapper classes « Utility Classes « SCJP






Integer and Long wrapper classes let you convert numbers in base 10 to other bases. 

public class MainClass{
    public static void main(String[] argv){

        String s3 = Integer.toHexString(254);  // convert 254 to hex
        System.out.println("254 is " + s3);    // result: "254 is fe"
        
        String s4 = Long.toOctalString(254); // convert 254 to octal
        System.out.print("254(oct) ="+ s4);  // result: "254(oct) =376"

    }
}
254 is fe
254(oct) =376








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.