Computer Applications
What important is automatically happening in following code ?
long a = 124235L;
Long b = new Long(a);
long c = b.longValue();
System.out.println(c);
Java Library Classes
5 Likes
Answer
Long b = new Long(a);
This statement boxes long type a into a Long object b, boxing a primitive type into a Wrapper class object.
long c = b.longValue();
This statement unboxes Long object b and stores it in long variable c, converting a Wrapper class object into a primitive data type.
Answered By
5 Likes
Related Questions
Find the error :
double n2 = Double.parseDouble("2"); double n3 = Double.parseDouble("OCA"); System.out.println(n2 + " " + n3);Predict the output :
double n1 = Double.parseDouble("8.0"); double n2 = Double.parseDouble("2"); System.out.println(n1 + " " + n2);Predict the output :
Integer c = 155; Integer d = 155; System.out.println(c == d); System.out.println(c.equals(d));In the following code, identify the statement where autoboxing is taking place :
Integer i = new Integer(10); if (i < 100) System.out.println(i); else System.out.println(i + 10);