Candibiotic
News Update :

English Premier League

Bundesliga

La Liga

Showing posts with label Iterator. Show all posts
Showing posts with label Iterator. Show all posts

Iterator

Thursday, August 20, 2009

An iterator provides the necessary behavior to get to each element in a collection without exposing the collection itself. In classes containing and manipulating collections, it is good practice to return an iterator instead of the collection containing the elements you want to iterate over. This shields clients from internal changes to the data structures used in your classes

Iterator Usage

Wednesday, June 24, 2009

import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;

public class IteratorUsage {

public static void main(String[] args) {
// created a sorted tree set
Set elementSet = new TreeSet();
elementSet.add("A");
elementSet.add("B");
elementSet.add("C");
// create a iterator
Iterator itr = elementSet.iterator();
// Iterate
while (itr.hasNext()) {
String value = itr.next();
System.out.println(value);
}
}
}

Football News

 

© Copyright Vinayak Wins 2010 -2011 | Design by Herdiansyah Hamzah | Published by Borneo Templates | Powered by Blogger.com.