AutoBox1.java
Select all
/* AutoBox1.java CIS 260 2/16/2005 David Klick Demonstrates the new Java 1.5 autoboxing feature whereby Java automatically converts primitives into appropriate wrapper objects and vice versa.. */ import java.util.*; public class AutoBox1 { public static void main(String[] args) { // v.add() requires an Object reference // Java does this conversion for us now // Java also converts it back to an int // when we add it to the accumulator Vector
v = new Vector
(); for (int i=0; i<100; i+=10) v.add(i); int sum = 0; for (int j=0; j