Are there cards in the Framework Collection?

Maps in Java are not inherited from the Collection interface, although most online guides explain Maps in the same category as Sets, Lists, and Queues.

However, do maps still belong to the Framework collection?

+4
source share
5 answers

The best description of the collection is at the beginning of the Java Assembly Tutorial .

A collection, sometimes called a container, is simply an object that groups several elements into one unit. Collections are used to store, retrieve, manipulate and share aggregate data. Typically, they represent data elements that form a natural group, such as a poker hand (collection of cards), a mail folder (collection of letters) or a telephone directory (matching names to phone numbers).

In addition, the tutorial lists the interfaces of the main collection, which all follow the paradigm described above:

The following list describes the collector interfaces:

Collection is the root of the collection hierarchy. A collection is a group of objects known as its elements. The Collection interface is the least common denominator that is implemented by all collections and is used to transfer and manipulate collections when maximum community is required. Some types of collections allow you to duplicate items, while others do not. Some are ordered, while others are unordered. The Java platform does not provide any direct implementations of this interface, but provides an implementation of more specific subinterfaces, such as Set and List. Also see Section "Collection Interface".

Set - a collection that cannot contain duplicate elements. This interface models a mathematical abstract abstraction and is used to represent sets, such as poker hands, courses that schedule students, or processes that run on a machine. See also the section "Configuring the interface".

A list is an ordered collection (sometimes called a sequence). Lists may contain duplicate items. The user of the list usually has precise control over where each element is inserted in the list, and can access the elements by their integer index (position). If you used Vector, you are familiar with the general flavor of List. Also see the section "List Interface".

A queue is a collection used to store several items before processing. In addition to basic collection operations, the queue provides additional insert, retrieve, and validate operations.

Queues usually, but not necessarily, arrange items in FIFO (first-in, first-out). Among the exceptions are priority queues that order the elements according to the provided comparator or the natural ordering of the elements. Regardless of the order used, the head of the queue is the item that will be deleted by the call to delete or poll. In the FIFO queue, all new items are inserted at the tail of the queue. Other types of queues may use different allocation rules. Each Queue implementation must specify its ordering properties. Also see Section "Queue Interface".

A map is an object that maps keys to values. The card cannot contain duplicate keys; each key can display no more than one value. If you used Hashtable, you are already familiar with the basics of Maps. Also see the section "Map Interface".

So, Map is a collection, although you really don't need to implement the Collection interface.

+3
source

The map interface is not an extension of the Collection interface. Instead, the interface begins its own interface hierarchy to support key value associations.

+2
source

Check out the official tutorial especially Lesson: Interfaces :

[...] The main collection interfaces are the foundation of the Java Collection Framework. As you can see in the following figure, collective collection interfaces form a hierarchy.

collections hierarchy

and further:

The following list describes the collector interfaces:

  • Collection [...]

  • Set [...]

  • List [...]

  • Queue [...]

  • Map [...]

+1
source

Conceptual maps are certainly collections since Smalltalk. The Java type hierarchy is not intended to manage conceptual relationships , but rather to pragmatic relationships, in particular, to say which methods should be implemented.

For card-like collections, they are very different from non-card types. For example, with maps that you must supply (key, value) and get (key) (or similar if you work with asscociation objects), while non-map-like should have iterator () and add ().

+1
source

The reason is that Collections work with a set of values, where they work as Key-Value pairs as Maps.

0
source

Source: https://habr.com/ru/post/1396575/


All Articles