MCPcopy Index your code
hub / github.com/BruceEckel/OnJava8-Examples / main

Method main

collections/SimpleIteration.java:9–28  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

7
8public class SimpleIteration {
9 public static void main(String[] args) {
10 List<Pet> pets = new PetCreator().list(12);
11 Iterator<Pet> it = pets.iterator();
12 while(it.hasNext()) {
13 Pet p = it.next();
14 System.out.print(p.id() + ":" + p + " ");
15 }
16 System.out.println();
17 // A simpler approach, when possible:
18 for(Pet p : pets)
19 System.out.print(p.id() + ":" + p + " ");
20 System.out.println();
21 // An Iterator can also remove elements:
22 it = pets.iterator();
23 for(int i = 0; i < 6; i++) {
24 it.next();
25 it.remove();
26 }
27 System.out.println(pets);
28 }
29}
30/* Output:
310:Rat 1:Manx 2:Cymric 3:Mutt 4:Pug 5:Cymric 6:Pug

Callers

nothing calls this directly

Calls 7

listMethod · 0.80
printMethod · 0.80
nextMethod · 0.65
iteratorMethod · 0.45
hasNextMethod · 0.45
idMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected