Iterating over generic list


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your HTML
  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

You need to login to post a comment.