View Source

h3.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]
* [#Interfaces]

h5.Algorithms


* [PhoneList.java|http://java.sun.com/new2java/supplements/solutions/July02.html] shows how to use a linked hash map to maintain a phone list. For supporting information see [New to Java Programming Supplement, July 2002|http://java.sun.com/new2java/supplements/2002/July02.html].

* [Sort.java|http://java.sun.com/docs/books/tutorial/collections/algorithms/examples/Sort.java] prints its arguments in alphabetical order. For supporting information see [The Java Tutorial Continued: Collections|http://java.sun.com/docs/books/tutorial/collections/algorithms/].

h5.Interfaces

* [CreatingCollections.java|http://java.sun.com/new2java/supplements/2002/CreatingCollections.java] creates a list and iterates through it. For supporting information see [New to Java Programming Supplement, March 2002|http://java.sun.com/new2java/supplements/2002/mar02.html].

* [Deal.java|http://java.sun.com/docs/books/tutorial/collections/interfaces/examples/Deal.java] generates hands from a 52 card deck. For supporting information see [The Java Tutorial Continued: Collections|http://java.sun.com/docs/books/tutorial/collections/algorithms/].

* [FindDups.java|http://java.sun.com/docs/books/tutorial/collections/interfaces/examples/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|http://java.sun.com/docs/books/tutorial/collections/algorithms/].

* [FindDups2.java|http://java.sun.com/docs/books/tutorial/collections/interfaces/examples/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|http://java.sun.com/docs/books/tutorial/collections/algorithms/].

* [Freq.java|http://java.sun.com/docs/books/tutorial/collections/interfaces/examples/Freq.java] generates a frequency table of the words found in its argument list. For supporting information see [The Java Tutorial Continued: Collections|http://java.sun.com/docs/books/tutorial/collections/algorithms/].

* [Name.java|http://java.sun.com/docs/books/tutorial/collections/interfaces/examples/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|http://java.sun.com/docs/books/tutorial/collections/algorithms/].

* [Shuffle.java|http://java.sun.com/docs/books/tutorial/collections/interfaces/examples/Shuffle.java] prints words in its argument list in random order. For supporting information see [The Java Tutorial Continued: Collections|http://java.sun.com/docs/books/tutorial/collections/algorithms/].


----

The individuals who post here are part of the extended Sun Microsystems community and they might not be employed or in any way formally affiliated with Sun Microsystems. The opinions expressed here are their own, are not necessarily reviewed in advance by anyone but the individual authors, and neither Sun nor any other party necessarily agrees with them.

Copyright 1994-2009 Sun Microsystems, Inc.
Powered by Atlassian Confluence
Sun Guidelines on Public Discourse Privacy Policy Terms of Use Trademarks Site Map Employment Investor Relations Contact