Friday, 13 May 2016

Java Tutorial : Java Unboxing

UnBoxingDemo.java
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;
    }

}
Output
absolute value of -8 = 8
doubleValue = 12.3
Click the below link to download the code:
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:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment

    Google+ Followers

    Google+ Badge