Java - Declare Generic List to store Integer object only

Description

Declare Generic List to store Integer object only

Demo

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

class Generic {/*  w ww.j  av a 2 s  .c om*/
  public static void main(String[] args) {
    List<Integer> l = new ArrayList<Integer>();
    l.add(1);
    l.add(2);
    l.add(3);

    Iterator<Integer> i = l.iterator();
    while(i.hasNext()) {
      System.out.println(i.next());
    }
  }
}

Related Topic