parseXxx() returns the named primitive.
valueOf() returns a newly created wrapped object of the type that invoked the method.
public class MainClass{
public static void main(String[] argv){
double d4 = Double.parseDouble("3.14");
System.out.println("d4 = " + d4);
Double d5 = Double.valueOf("3.14");
System.out.println(d5 instanceof Double);
//involve using the radix argument (in this case binary):
long L2 = Long.parseLong("101010", 2);
System.out.println("L2 = " + L2);
Long L3 = Long.valueOf("101010", 2);
System.out.println("L3 value = " + L3);
}
}
|