|
Auto Boxing Features
This example shows auto-boxing/auto-unboxing features of Java5.
|
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
|
|