Collections Framework Code Samples
In the Java programming language, collections are objects that group multiple elements into a single unit. Collections let you store, retrieve, and manipulate data, and transmit data from one method to another.
Algorithms
- PhoneList.java shows how to use a linked hash map to maintain a phone list. For supporting information see New to Java Programming Supplement, July 2002.
- Sort.java prints its arguments in alphabetical order. For supporting information see The Java Tutorial Continued: Collections.
Interfaces
- CreatingCollections.java creates a list and iterates through it. For supporting information see New to Java Programming Supplement, March 2002.
- Deal.java generates hands from a 52 card deck. For supporting information see The Java Tutorial Continued: Collections.
- FindDups.java takes words in its argument list and prints out any duplicate words, the number of distinct words, and a list of the words with duplicates eliminated. For supporting information see The Java Tutorial Continued: Collections.
- FindDups2.java finds the words in the argument list that occur once, that occur more than once, and does not print out duplicate words repeatedly. For supporting information see The Java Tutorial Continued: Collections.
- Freq.java generates a frequency table of the words found in its argument list. For supporting information see The Java Tutorial Continued: Collections.
- Name.java compares names and returns a value indicating the comparison results: negative integer for less than, zero for equal to, or positive integer for greater than. For supporting information see The Java Tutorial Continued: Collections.
- Shuffle.java prints words in its argument list in random order. For supporting information see The Java Tutorial Continued: Collections.