Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Código do post "Iteração interna com Java 8 e métodos default": http://alexandreaquiles.com.br/2014/03/24/iteracao-interna-com-java-8-e-metodos-default/
import java.util.*;
class ProgramaComForEach {
public static void main(String[] args){
List<String> personagens = Arrays.asList("Pato Donald", "Mickey", "Pateta", "Pluto");
for(int i = 0; i < personagens.size(); i++){
String personagem = personagens.get(i);
System.out.println(personagem);
}
System.out.println("-----------");
for(Iterator<String> it = personagens.iterator(); it.hasNext();){
String personagem = it.next();
System.out.println(personagem);
}
System.out.println("-----------");
for(String personagem : personagens){
System.out.println(personagem);
}
System.out.println("-----------");
personagens.forEach(personagem -> System.out.println(personagem));
System.out.println("-----------");
personagens.forEach(System.out::println);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.