Questions tagged [collections]

Collections APIs provide developers with a set of classes and interfaces that make it easier to handle collections of objects.

Collections APIs provide developers with a set of classes and interfaces that make it easier to handle collections of objects. In a sense, collections work a bit like , except their size can change dynamically, and they have more advanced behaviour than arrays.

In

There is a standard C library, GLib, that provides lists, hash tables, growable arrays, trees, simple and multi-key maps and some uncommon collections like quarks, keyed lists and memory chunks.

In

C++ Container framework provides vectors (sizeable arrays), queues, lists, stacks, sets and maps. Maps in this framework may have multiple keys.

In

Java collections framework provides sets, lists, hash tables, ordered (linked) hash tables, stacks and queues. There are also specialized collections to work with multiple threads (blocking queues, etc).

There are three main types of collections:

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

In

The .NET Framework provides specialized classes for data storage and retrieval. These classes provide support for stacks, queues, lists, and hash tables. Most collection classes implement the same interfaces, and these interfaces may be inherited to create new collection classes that fit more specialized data storage needs.

System.Collections Namespace

Collections (C#)

Collections (Visual Basic)

Some Popular Questions in Stackoverflow:

23956 questions
13
votes
4 answers

Java equivalent of std::deque

I'm a relatively new Java programmer coming from C++/STL, and am looking for a class with these characteristics (which the C++ std::deque has, as I understand it): O(1) performance for insertion/removal at the beginning/end O(1) performance for…
Jason S
  • 184,598
  • 164
  • 608
  • 970
13
votes
2 answers

Java 8 streams on string arrays

I have a single String of format: row1col1 row1col2 row2col1 row2col2 row3col1 row3col2 and so on... I want to extract each item and build an array of objects with properties like this: new MyObject(row1col1, row1col2); I am new to Java 8 and…
Lucian Enache
  • 2,510
  • 5
  • 34
  • 59
13
votes
2 answers

How to distinguish between live and non-live NodeList collections?

Both document.getElementsByTagName('div') and document.querySelectorAll('div') return NodeList collection. The only difference is that first method returns live-collection and second one - a static one. The question is - is there any opportunity to…
shabunc
  • 23,119
  • 19
  • 77
  • 102
13
votes
4 answers

How to print address of a variable in Java

As an address of a variable (i.e. int a) in C can be obtained by &a. How can this be done in Java? For Eg. The elements of a linked list are non-contiguous. How can we print the address of the elements of a linked list created using the Collections…
h8pathak
  • 1,342
  • 3
  • 17
  • 29
13
votes
3 answers

Does Oracle 12 have problems with local collection types in SQL?

To make a long story short I propose to discuss the code you see below. When running it: Oracle 11 compiler raises "PLS-00306: wrong number or types of arguments tips in call to 'PIPE_TABLE'" "PLS-00642: Local Collection Types Not Allowed in SQL…
diziaq
  • 6,881
  • 16
  • 54
  • 96
13
votes
5 answers

Which is faster, the List.Remove(T) or List.RemoveAt(int) method?

Is List.Remove(T) faster than the List.RemoveAt(int) method in .NET collections? Is speed different for value types or reference types?
abenci
  • 8,422
  • 19
  • 69
  • 134
13
votes
11 answers

Java + Count duplicates from int array without using any Collection or another intermediate Array

As a part of the Java interview question paper I have got following issue to solve. But I am bit wonder whether how can I implement it without any Collection or intermediate Array. Question:- Count duplicates from int array without using any…
Channa
  • 4,963
  • 14
  • 65
  • 97
13
votes
2 answers

How to add null values to ConcurrentHashMap

I have a ConcurrentHashMap which is called from different threads to put values in it. I have to insert null values, but ConcurrentHashMap doesn't allow null values. Is there a way to do that or an alternate option to do this in Java?
Khawar Ali
  • 3,462
  • 4
  • 27
  • 55
13
votes
1 answer

Is there a collection that behaves like a Queue but allows me to get multiple elements at a time?

I am looking for a data structure that behaves like a queue (it could be a queue implementation) but allows me to get multiple elements from the collection (example: the first 15 elements of the queue). It would be very nice if it doesn't require…
JSBach
  • 4,679
  • 8
  • 51
  • 98
13
votes
5 answers

Why does the Collections class contain standalone (static) methods, instead of them being added to the List interface?

For all the methods in Collections that take a List as their first argument, why aren't those methods simply part of the List interface? My intuition is: given a List object, that object itself should "know" how to perform on itself operations such…
Aaron Fi
  • 10,116
  • 13
  • 66
  • 91
13
votes
1 answer

Mapping a list to Map Java 8 stream and groupingBy

I have this simple Bean class: public class Book { public Book(Map attribute) { super(); this.attribute = attribute; } //key is isbn, val is author private Map attribute; public Map
daman
  • 309
  • 2
  • 5
  • 13
13
votes
5 answers

How can you reverse traverse through a C# collection?

Is it possible to have a foreach statement that will traverse through a Collections object in reverse order? If not a foreach statement, is there another way?
Sam F
  • 621
  • 1
  • 8
  • 16
13
votes
8 answers

Genericized commons collection

I'm astonished that the Apache Commons Collections project still hasn't got around to making their library generics-aware. I really like the features provided by this library, but the lack of support for generics is a big turn-off. There is a…
Dónal
  • 185,044
  • 174
  • 569
  • 824
13
votes
1 answer

C# equivalent of LinkedHashMap

As the question says, I'm looking for the c# equivalent of the LinkedHashMap in Java. I need to be able to retrieve keys and values by index, get the size. I need the elements to be ordered in the way they are inserted. One key should be matched to…
Hele
  • 1,558
  • 4
  • 23
  • 39
13
votes
2 answers

In Java Collections Map What does "?" refer to?

In Java Collections I saw something like this: Map. I don't know how it is working, can anyone help me out with this or provide an example?
Gowtham Murugesan
  • 407
  • 2
  • 6
  • 17