Posted By

cetnar on 07/11/06


Tagged

list generics tiger


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

xaviaracil
jonbaer


Iterating over generic list


 / Published in: Java
 

  1. List<String> listOfStrings = new LinkedList<String>( );
  2.  
  3. listOfStrings.add("Happy");
  4.  
  5. listOfStrings.add("Birthday");
  6.  
  7. listOfStrings.add("To");
  8.  
  9. listOfStrings.add("You");
  10.  
  11.  
  12.  
  13. for (Iterator<String> i = listOfStrings.iterator( ); i.hasNext( ); ) {
  14.  
  15. String s = i.next( );
  16.  
  17. out.println(s);
  18.  
  19. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: fuzzylollipop on November 13, 2009

actually the following is simpler and more appropriate in 1.5 and above

for (final String s : listOfStrings) { System.out.println(s); }

You need to login to post a comment.