Java Collections Framework - Architecture

Architecture

Almost all collections in Java are derived from the java.util.Collection interface. Collection defines the basic parts of all collections. The interface states the add and remove methods for adding to and removing from a collection 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 java.util.Iterable, so any Collection may be the target of a for-each statement. (The Iterable interface provides the iterator method used by for-each statements.) 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 can hold strings, and the elements from the collection can be used as strings without any casting required.

There are three main types of collections:

  • Lists: always ordered, may contain duplicates and can be handled the same way as usual arrays
  • Sets: cannot contain duplicates and provide random access to their elements
  • Maps: connect unique keys with values, provide random access to its keys and may host duplicate values

Read more about this topic:  Java Collections Framework

Famous quotes containing the word architecture:

    The two elements the traveler first captures in the big city are extrahuman architecture and furious rhythm. Geometry and anguish. At first glance, the rhythm may be confused with gaiety, but when you look more closely at the mechanism of social life and the painful slavery of both men and machines, you see that it is nothing but a kind of typical, empty anguish that makes even crime and gangs forgivable means of escape.
    Federico García Lorca (1898–1936)

    The principle of the Gothic architecture is infinity made imaginable.
    Samuel Taylor Coleridge (1772–1834)

    Art is a jealous mistress, and if a man have a genius for painting, poetry, music, architecture or philosophy, he makes a bad husband and an ill provider, and should be wise in season and not fetter himself with duties which will embitter his days and spoil him for his proper work.
    Ralph Waldo Emerson (1803–1882)