Created
April 19, 2012 13:20
-
-
Save iande/2420945 to your computer and use it in GitHub Desktop.
Boxing and Unboxing example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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