Correct collection definition in java

While reading collections in java and looking at some stackoverflow questions, I came across this question:

Method for adding objects to a fixed collection (Array) in Java

Here Array is referred to as a fixed collection. Is it conceptually legal to call an array a "fixed collection" or is this a contradictory phrase?

+3


source to share


2 answers


A collection structure is basically a structure for storing and retrieving a collection of Java objects efficiently.

A very good link about an overview of the data structure here

According to this link



There are fourteen collection interfaces. The simplest interface is Collection. These interfaces extend Collection: Set, List, SortedSet, NavigableSet, Queue, Deque, BlockingQueue, and BlockingDeque. The other collection interfaces, Map, SortedMap, NavigableMap, ConcurrentMap, and ConcurrentNavigableMap, do not propagate Collection as they are mappings and not actual collections. However, these interfaces contain collection browsing operations that allow them to be manipulated like collections.

Now, back to an array that is not part of the collection framework, but logically its collection, since it can store a collection of objects. Even if you develop your own class that can store a bunch of objects, you can logically call it a collection object.

+2


source


An array is a collection if you define a collection as a container of items.



Of course, an array doesn't implement the Collection interface, but calling Arrays.asList(arr)

on an array actually gives you a fixed list view of that array's list, so you can say that an array is almost equivalent to a fixed length random access list (List is a collection).

+2


source







All Articles