bbrother92
12/18/2016 - 9:43 PM

#collections

#collections

public class Main {
	
	public static void main(String... args) {
		Box bx = new Box();
		for (Human o : bx) {
			System.out.println(o);
		}
	}
}

class Box implements Iterable<Human> {
	Human[] items = {new Human("John"), new Human("Bernard"), new Human("Marlon")};
	
	@Override
	public Iterator iterator() {
		return new Iterator() {
			int index = 0;
			
			@Override
			public boolean hasNext() {
				
				return index < items.length;
			}
			
			@Override
			public Object next() {
				return items[index++];
			}
		};
	}
	
	
}

class Human {
	String name;
	
	public Human(String name) {
		this.name = name;
	}
	
	@Override
	public String toString() {
		return name.toString();
	}