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

Class IterableClass

collections/IterableClass.java:8–30  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6import java.util.*;
7
8public class IterableClass implements Iterable<String> {
9 protected String[] words = ("And that is how " +
10 "we know the Earth to be banana-shaped."
11 ).split(" ");
12 @Override public Iterator<String> iterator() {
13 return new Iterator<String>() {
14 private int index = 0;
15 @Override public boolean hasNext() {
16 return index < words.length;
17 }
18 @Override
19 public String next() { return words[index++]; }
20 @Override
21 public void remove() { // Not implemented
22 throw new UnsupportedOperationException();
23 }
24 };
25 }
26 public static void main(String[] args) {
27 for(String s : new IterableClass())
28 System.out.print(s + " ");
29 }
30}
31/* Output:
32And that is how we know the Earth to be banana-shaped.
33*/

Callers

nothing calls this directly

Calls 1

splitMethod · 0.80

Tested by

no test coverage detected