Saturday, October 20, 2007

Iterator Example


import java.util.*;

public class HashSetIterator {

 /**
  * @A.J, CH 15
  */
 public static void main(String[] args) {
  
  HashSet s = new HashSet();
  
  s.add("House");
  s.add("of");
  s.add("fun");
  s.add("believe");
  s.add("Shame");
  s.add("woke");
  
  System.out.println("The Set Contains: ");
  
  Iterator i = s.iterator();
  while (i.hasNext())
   System.out.println (i.next());
  
  System.out.println("****End of Contents***");
  i.remove();
  
  System.out.println();
  System.out.println("The Set _now_ Contains: ");
  
  Iterator z = s.iterator();
  while (z.hasNext())
   System.out.println (z.next());
  
  System.out.println("****End of Contents***");
  System.out.println();
  System.out.println();
  System.out.println("The Java Instructions have come to an END.");
  

 }

}

/*
The Set Contains: 
of
woke
House
fun
believe
Shame
****End of Contents***

The Set _now_ Contains: 
of
woke
House
fun
believe
****End of Contents***


The Java Instructions have come to an END.
*/

No comments:

Just some daily notes ...

Powered By Blogger