for loop


stáhnout snippet
zobrazení: SyntaxHighlighter | GeSHi | Holý text
public class Main {

	public static void main(String[] args) throws Exception {

		Balls b = new Balls() {

			List l = new ArrayList<Integer>();
			{
				l.add(1);
				l.add(2);
				l.add(3);
				l.add(4);
			}
			Iterator<Integer> i = l.iterator();

			public Integer next() {
				return i.hasNext() ? i.next() : null;
			}
		};

		for (Integer i = b.next(); i != null; i = b.next()) {
			System.out.println("works :" + i);
		}
	}

	interface Balls {
		Integer next();
	}
}


java 29 řádků | 2011-10-07 23:59:17