Container (data structure)

From Wikipedia, the free encyclopedia

(Redirected from Container (programming))
Jump to: navigation, search

In computer science, a container is a class, a data structure, or an abstract data type (ADT) whose instances are collections of other objects. They are used to store objects in an organized way following specific access rules.

Generally, container classes are expected to implement methods to do the following:

  • create a new empty container (constructor),
  • report the number of objects it stores (size),
  • delete all the objects in the container (clear),
  • insert new objects into the container,
  • remove objects from it,
  • provide access to the stored objects.

There are two types of containers: value containers and reference containers.

Value based containers store copies of the objects. Accessing an object also returns a copy of it. Modifying an external object after it has been inserted in the container will not affect the content of the container.

Reference based containers only store pointers or references to the objects. Accessing an object returns a reference to it. Modifying an external object after it has been inserted in the container could result in modifying the content of the container (or more precisely, the object stored in the container).

Containers are sometimes implemented in conjunction with iterators.

Contents

Examples of container classes include

See also: Collection class

In object-oriented programming, a collection class is any class that is capable of storing other objects. Collection classes usually implement some kind of data structure, such as a list, map, set, array, or tree. A collection class is usually able to store an arbitrary number of data items, i.e. the size of the collection is adjusted automatically.

Widget toolkits use special widgets also called Containers to group the other widgets together (windows, panels, ...). Apart from their graphical properties, they have the same type of behavior as container classes, as they keep a list of their child widgets, and allow to add, remove, or retrieve widgets amongst their children.

The Java Collections Framework, as well as the standard C++ library's Standard Template Library provides APIs and implementations for many kinds of container classes.

Advanced Search
Included Web Search Engines


Safe Search

close

Top Matching Results

Occasionally Search.com will highlight specialized results that are based on the context of your query. Examples of specialized results include specific links to news, images, or video.

Top Matching Results may highlight information from other Search.com pages, content from the CNET Network of sites, or third party content. The listings are based purely on relevance. Search.com does not receive payment for listings in this section but our partners that provide this data may get paid for listing these products.

Sponsored Links

This section contains paid listings which have been purchased by companies that want to have their sites appear for specific search terms and related content. These listings are administered, sorted and maintained by a third party and are not endorsed by Search.com.

Search Results

Search.com sends your search query to several search engines at one time and integrates the results into one list which has been sorted by relevance using Search.com's proprietary algorithm. You can customize the list of search engines included in your metasearch from the preferences.

The search engines that are used in your metasearch may allow companies to pay to have their Web sites included within the results. To view the Paid Inclusion policy for a specific search engine, please visit their Web site. Search.com does not accept payment or share revenue with any search engine partner for listings in this section.