Methods Summary |
---|
public static void | main(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 void | someCollectionMethod(java.lang.String prefix)Collection usage with JDK 1.4 and below.
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 void | someMethod(java.lang.String prefix)Array usage prior to Tiger.
for (int idx = 0; idx < importantPeople.length; idx++) {
if (importantPeople[idx].startsWith(prefix)) {
System.out.print(importantPeople[idx] + " ");
}
}
System.out.println();
|
public static void | someTigerCollectionMethod(java.lang.String prefix)Collection usage with Tiger.
List<String> people = Arrays.asList(importantPeople);
for (String person: people) {
if (person.startsWith(prefix)) {
System.out.print(person + " ");
}
}
System.out.println();
|
public static void | someTigerMethod(java.lang.String prefix)Array usage with Tiger.
for (String person: importantPeople) {
if (person.startsWith(prefix)) {
System.out.print(person + " ");
}
}
System.out.println();
|