21 lines
547 B
Java
21 lines
547 B
Java
// generics/ListOfInt.java
|
|
// (c)2016 MindView LLC: see Copyright.txt
|
|
// We make no guarantees that this code is fit for any purpose.
|
|
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
|
|
// Autoboxing compensates for the inability to use
|
|
// primitives in generics.
|
|
import java.util.*;
|
|
|
|
public class ListOfInt {
|
|
public static void main(String[] args) {
|
|
List<Integer> li = new ArrayList<>();
|
|
for(int i = 0; i < 5; i++)
|
|
li.add(i);
|
|
for(int i : li)
|
|
System.out.print(i + " ");
|
|
}
|
|
}
|
|
/* Output:
|
|
0 1 2 3 4
|
|
*/
|