tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 
 Java > Core > Boolean > Auto Boxing Features

Auto Boxing Features 

This example shows auto-boxing/auto-unboxing features of Java5.

File Name  :  
com/bethecoder/tutorials/core/bool/BooleanAutoBox.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.core.bool;

import java.util.ArrayList;
import java.util.List;

public class BooleanAutoBox {

  /**
   @param args
   */
  public static void main(String[] args) {
    boolean bool = false
    List<Boolean> boolList = new ArrayList<Boolean>();
    boolList.add(bool);    //Auto boxing to a Boolean object
    boolList.add(true);    //Auto boxing to a Boolean object  
    System.out.println(boolList);
    
    Boolean bool2 = new Boolean("true");
    
    if (bool2) {       //Auto un-boxing to a boolean primitive
      System.out.println("bool is true");
    }
    
  }

}
   

It gives the following output,
[false, true]
bool is true


                    Print

   



Books Recommendation

 
 
bl  br