Enumeration/Enum Spanning
21 June 2008Spanning enum in Java 1.5 is easy using for loop.
enum Breed { DALMATIAN, LABRADOR, DACHSHUND } ... for ( Breed dog : Breed.values() ) { System.out.println( dog ); }
Let me show hot to span an enumeration.
for ( Enumeration e = props.propertyNames(); e.hasMoreElements(); ) { String key = (String) e.nextElement(); System.out.println( key ); }
We may use iterator to span a list. Iterator’s next method is used to get the next value and hasNext method is use to check if the iterator has next element or not. Yes, it returns bool value.
for ( Iterator iter = list.iterator(); iter.hasNext(); ) { String key = (String)iter.next(); System.out.println( key ); }
Related Posts:
Top Of Page | Trackback
If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.
It will look like this: Enumeration/Enum Spanning