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
820
votes
10 answers

How to convert Set to Array?

Set seems like a nice way to create Arrays with guaranteed unique elements, but it does not expose any good way to get properties, except for generator [Set].values, which is called in an awkward way of mySet.values.next(). This would have been ok,…
c69
  • 19,951
  • 7
  • 52
  • 82
802
votes
13 answers

How do I convert a Map to List in Java?

How do I convert a Map to a List? Should I iterate over all map values and insert them into a list?
Javaa
  • 8,059
  • 3
  • 17
  • 5
763
votes
30 answers

How to filter a Java Collection (based on predicate)?

I want to filter a java.util.Collection based on a predicate.
Kevin Wong
  • 14,656
  • 11
  • 42
  • 52
759
votes
17 answers

Easiest way to convert a List to a Set in Java

What is the easiest way to convert a List to a Set in Java?
OHHAI
  • 7,845
  • 5
  • 19
  • 9
757
votes
16 answers

How can I convert List to int[] in Java?

How can I convert a List to int[] in Java? I'm confused because List.toArray() actually returns an Object[], which can be cast to neither Integer[] nor int[]. Right now I'm using a loop to do so: int[] toIntArray(List list) { …
unknown
730
votes
20 answers

How do I remove an array item in TypeScript?

I have an array that I've created in TypeScript and it has a property that I use as a key. If I have that key, how can I remove an item from it?
Tim Almond
  • 12,088
  • 10
  • 40
  • 50
707
votes
13 answers

Ways to iterate over a list in Java

Being somewhat new to the Java language I'm trying to familiarize myself with all the ways (or at least the non-pathological ones) that one might iterate through a list (or perhaps other collections) and the advantages or disadvantages of each.…
jacobq
  • 11,209
  • 4
  • 40
  • 71
684
votes
10 answers

Why there is no ConcurrentHashSet against ConcurrentHashMap

HashSet is based on HashMap. If we look at HashSet implementation, everything is been managed under HashMap. is used as a key of HashMap. And we know that HashMap is not thread safe. That is why we have ConcurrentHashMap in…
Talha Ahmed Khan
  • 15,043
  • 10
  • 42
  • 49
656
votes
34 answers

Java 8 Distinct by property

In Java 8 how can I filter a collection using the Stream API by checking the distinctness of a property of each object? For example I have a list of Person object and I want to remove people with the same name, persons.stream().distinct(); Will use…
RichK
  • 11,318
  • 6
  • 35
  • 49
646
votes
28 answers

How to convert comma-separated String to List?

Is there any built-in method in Java which allows us to convert comma separated String to some container (e.g array, List or Vector)? Or do I need to write custom code for that? String commaSeparated = "item1 , item2 , item3"; List items =…
Jame
  • 21,150
  • 37
  • 80
  • 107
620
votes
13 answers

Why is there no SortedList in Java?

In Java there are the SortedSet and SortedMap interfaces. Both belong to the Java Collections framework and provide a sorted way to access the elements. However, in my understanding there is no SortedList in Java. You can use…
Jijoy
  • 12,386
  • 14
  • 41
  • 48
607
votes
6 answers

Is there a short contains function for lists?

Given a list xs and a value item, how can I check whether xs contains item (i.e., if any of the elements of xs is equal to item)? Is there something like xs.contains(item)? For performance considerations, see Fastest way to check if a value exists…
Joan Venge
  • 315,713
  • 212
  • 479
  • 689
573
votes
40 answers

How do I remove repeated elements from ArrayList?

I have an ArrayList, and I want to remove repeated strings from it. How can I do this?
user25778
  • 5,901
  • 3
  • 20
  • 12
564
votes
21 answers

How to convert int[] into List in Java?

How do I convert int[] into List in Java? Of course, I'm interested in any other answer than doing it in a loop, item by item. But if there's no other answer, I'll pick that one as the best to show the fact that this functionality is not…
Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
560
votes
7 answers

C# Set collection?

Does anyone know if there is a good equivalent to Java's Set collection in C#? I know that you can somewhat mimic a set using a Dictionary or a HashTable by populating but ignoring the values, but that's not a very elegant way.
Omar Kooheji
  • 54,530
  • 68
  • 182
  • 238