FileDocCategorySizeDatePackage
ForEach.javaAPI DocExample3014Fri Nov 21 00:53:52 GMT 2003oreilly.hcj.tiger

ForEach

public class ForEach extends Object
Demonstration of the foreach facility of Tiger, JDK 1.5.

Fields Summary
public static final String[]
importantPeople
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

		if (args.length != 1) {
			System.out.println("usage: ForEach <string>");
			System.out.println("Where <string> is the prefix of names you wish to print.");
			System.exit(0);
		}
		System.out.println("The old way: ");
		someMethod(args[0]);	
		System.out.println("The new way: ");
		someTigerMethod(args[0]);	
		System.out.println("The old collection way: ");
		someCollectionMethod(args[0]);	
		System.out.println("The new collection way: ");
		someTigerCollectionMethod(args[0]);	
	
public static voidsomeCollectionMethod(java.lang.String prefix)
Collection usage with JDK 1.4 and below.

param
prefix The prefix of the names to print.

		List people = Arrays.asList(importantPeople);
		Iterator iter = people.iterator();
		for (String person = (String)iter.next(); iter.hasNext(); 
		     person = (String)iter.next()) {
			if (person.startsWith(prefix)) {
				System.out.print(person + " ");
			}
		}
		System.out.println();
	
public static voidsomeMethod(java.lang.String prefix)
Array usage prior to Tiger.

param
prefix The prefix of the names to print.


	              	 
	      
		for (int idx = 0; idx < importantPeople.length; idx++) {
			if (importantPeople[idx].startsWith(prefix)) {
				System.out.print(importantPeople[idx] + " ");
			}
		}
		System.out.println();
	
public static voidsomeTigerCollectionMethod(java.lang.String prefix)
Collection usage with Tiger.

param
prefix The prefix of the names to print.

		List<String> people = Arrays.asList(importantPeople);
		for (String person: people) {
			if (person.startsWith(prefix)) {
				System.out.print(person + " ");
			}
		}
		System.out.println();
	
public static voidsomeTigerMethod(java.lang.String prefix)
Array usage with Tiger.

param
prefix The prefix of the names to print.

		for (String person: importantPeople) {
			if (person.startsWith(prefix)) {
				System.out.print(person + " ");
			}
		}
		System.out.println();