Computer Science 210
Data Structures

Fall 2017, Siena College

Iterables BlueJ Project

Click here to download a BlueJ project for Iterables.


Iterables Source Code

The Java source code for Iterables is below. Click on a file name to download it.


Iterables.java

/*
  Example to demonstrate use of Iterables and "for each"
  loops in Java 5 and up.

  Jim Teresco, Mount Holyoke College, CS 211, Fall 2009
  Siena College, CSIS 210, Fall 2016, Fall 2017
*/
import structure5.*;

public class Iterables {

    public static void main(String args[]) {
	Vector<Integer> v = new Vector<Integer>();

	for (int i=0; i<10; i++) {
	    v.add(i*i);
	}

	/* enhanced for loop ! -- works if v implements Iterable */
	for (int i : v) {
	    System.out.println(i);
	}
    }
}