Skip to content

Instantly share code, notes, and snippets.

@iande
Created April 19, 2012 13:20
Show Gist options
  • Save iande/2420945 to your computer and use it in GitHub Desktop.
Save iande/2420945 to your computer and use it in GitHub Desktop.
Boxing and Unboxing example
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
ArrayList<Integer> myList = new ArrayList<Integer>();
myList.add(new Integer(10));
myList.add(new Integer(11));
myList.add(new Integer(12));
int listSum = 0;
for(Integer val : myList) {
listSum += val.intValue();
}
System.out.println("The sum of list is: " + listSum);
}
}
// The sum of the list is: 33
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
ArrayList<Integer> myList = new ArrayList<Integer>();
myList.add(10);
myList.add(11);
myList.add(12);
int listSum = 0;
for(int val : myList) {
listSum += val;
}
System.out.println("The sum of list is: " + listSum);
}
}
// The sum of the list is: 33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment