Click here to watch in Youtube :
https://www.youtube.com/watch?v=zqjl1ElyC2c&list=UUhwKlOVR041tngjerWxVccw
import java.util.ArrayList; import java.util.List; public class UnBoxingDemo { public static void main(String[] args) { Integer integerObj = new Integer(-8); // 1. Unboxing through method invocation int absVal = absoluteValue(integerObj); System.out.println("absolute value of " + integerObj + " = " + absVal); List<Double> list = new ArrayList<>(); list.add(new Double(12.3)); // 2. Unboxing through assignment double doubleValue = list.get(0); System.out.println("doubleValue = " + doubleValue); } public static int absoluteValue(int i) { return (i < 0) ? -i : i; } }
absolute value of -8 = 8 doubleValue = 12.3
https://sites.google.com/site/javaee4321/java/UnBoxingDemo_App.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/UnBoxingDemo_App
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/c539eeaf4c6ff331d8e2aa2333826ea70c999093/BasicJava/UnBoxingDemo_App/?at=master
See also:
No comments:
Post a Comment