// // Example of using Vector class for integers. // // Usage: // java TryIntList i1 i2 .... // where i1, i2, etc. are one or more integers. // // Description: // Builds a Vector containing i1, i2, etc., and tries out some // methods of the Collections class on it. // // Example of use: // java TryIntList 10 2 -4 20 15 12 // import java.util.*; public class TryIntList { public static void main(String[] args) { List l1 = new Vector(); for (int i = 0; i < args.length; ++i) { // can't put "int" in Vector -- must build // Integer object. l1.add(new Integer(args[i])); } System.out.println("contents of Vector:"); Iterator iter; iter = l1.iterator(); while (iter.hasNext()) System.out.println(iter.next()); System.out.println("minimum element = " + Collections.min(l1)); System.out.println("maximum element = " + Collections.max(l1)); Collections.sort(l1); System.out.println("contents of Vector, sorted:"); iter = l1.iterator(); while (iter.hasNext()) System.out.println(iter.next()); Collections.shuffle(l1); System.out.println("contents of Vector, shuffled:"); iter = l1.iterator(); while (iter.hasNext()) System.out.println(iter.next()); } }