ArrayList using iterator - Java @ Desk

Thursday, May 16, 2013

ArrayList using iterator











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

public class ArrayListIterator {
    public static void main(String args[]) {
        List<String> strings = new ArrayList<String>();
        strings.add("First Name");
        strings.add("Last Name");
        strings.add("Age");
        Iterator<String> iterator = strings.iterator();
        while(iterator.hasNext()) {
            System.out.println("Value : " +iterator.next());
        }
    }
}






No comments:

Post a Comment