Type conversion (JDK1.5)Tag(s): String/Number
JDK1.5 simplifies the operation of conversion between primitive types (such as int) and wrapper types (such as Integer). This feature is called Autoboxing/Unboxing.
public class Test15 { public static void main(String ... args) { Integer integer = 1; // int into Integer System.out.println(integer); int i = integer + 3; // mix Integer and ints System.out.println(i); // output : // 1 // 4 } }
import java.util.Collection.*; import java.util.*; public class Test15 { public static void main(String ... args) { ArrayList<Boolean> list = new ArrayList<Boolean>(); list.add(0, true); boolean flag = list.get(0); System.out.println(flag); } }
import java.util.Collection.*; import java.util.*; public class Test15 { public static void main(String args[]) { ArrayList list = new ArrayList(); list.add(0, new Boolean(true)); boolean flag = ((Boolean)list.get(0)).booleanValue(); System.out.println(flag); } }