Java collections framework

This is an old revision of this page, as edited by Ztothefifth (talk | contribs) at 18:06, 21 December 2010 (Collection Interface: contains() method). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

JCF redirects here and can also stand for Jordan canonical form in Linear Algebra or Juan Carlos Ferrero, the Spanish tennis player

The Java collections framework is a coupled set of classes and interfaces that implement commonly reusable collection data structures. It was designed and developed primarily by Joshua Bloch and introduced in JDK 1.2.

Although it is a framework, it works in a manner of a library. The JCF provides both interfaces that define various collections and classes that implement them.

Collection Interface

All collections in Java are derived from the Collection interface. Collection defines the basic parts of all collections. The interface states the add() and remove() methods for adding to and removing from an interface respectively. Also required is the toArray() method, which converts the collection into a simple array of all the elements in the collection. Finally, the contains() method checks if a specified element is in the collection. The Collection interface is a subinterface of Iterable, so the iterator() method is also provided. All collections have an iterator that goes through all of the elements in the collection. Additionally, Collection is a generic. Any collection can be written to store any class. For example, Collection<String> can hold strings, and the elements from the collection can be used as strings without any casting required.

See also