import java.util.*; /** * Store all the command line argument strings in each type of collection * to illustrate how the different types store the data differently. */ //Found at www.ajug.org. Thanks! public class CollectionTypes { public static void main(String args[]) { // Store args as list. List argsAsList = Arrays.asList(args); // Instantiate one each of all of the general collection implementations. Set set = new HashSet(argsAsList); SortedSet sortedSet = new TreeSet(); sortedSet.addAll(argsAsList); // Store args in map. Map map = new HashMap(); for (int i = 0; i < args.length; i++) { map.put(String.valueOf(i), args[i]); } // end for // Instantiate a sorted map from the unsorted map. SortedMap sortedMap = new TreeMap(); sortedMap.putAll(map); // Print out the contents of each collection/map. System.out.println("Set: " + set); System.out.println("SortedSet: " + sortedSet); System.out.println("List: " + argsAsList); System.out.println("Map: " + map); System.out.println("SortedMap: " + sortedMap); } }