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
15
votes
5 answers

Why doesn't IEnumerable have FindAll or RemoveAll methods?

It seems to me that a lot of the extension methods on IList are just as applicable to IEnumerable - such as FindAll and RemoveAll. Can anyone explain the reasoning why they are not there?
Andy
  • 10,412
  • 13
  • 70
  • 95
15
votes
5 answers

Maps (collection) that maintains insertion Order in java

I need to use Maps in Java for an Android Application. But the problem is that the list gets sorted automatically. How do I use Maps to get the data in the same order as I have inserted data.
Akhil K Nambiar
  • 3,835
  • 13
  • 47
  • 85
15
votes
5 answers

C# dictionary type with unique keys and values

I was wondering if there was a built in type in C# that was like 'Dictionary' but where both TKey and TValue had to be unique. For example:: d.Add(1, "1"); d.Add(2, "1"); // This would not be OK because "1" has already been used as a value. I know…
A.R.
  • 15,405
  • 19
  • 77
  • 123
15
votes
3 answers

How do I map a nested collection, Map>, with hibernate JPA annotations?

I have a class I am not sure how to annotate properly. My goal for Holder::data: List should maintain order not by comparator but by the natural ordering of the elements in the array. (Which can be an ndx column if that is helpful.) Holder will…
Nathan Feger
  • 19,122
  • 11
  • 62
  • 71
15
votes
5 answers

Why is Option not Traversable?

Is there any rational for Option not being Traversable? In Scala 2.9, Seq(Set(1,3,2),Seq(4),Option(5)).flatten doesn't compile and simply having it to implement the Traversable trait seams rational to me. If it's not the case, there must be…
shellholic
  • 5,974
  • 1
  • 20
  • 30
15
votes
2 answers

Why are collection initializers on re-assignments not allowed?

I always thought it worked fine both ways. Then did this test and realized it's not allowed on re-assignments: int[] a = {0, 2, 4, 6, 8}; works fine but not: int [ ] a; a = { 0, 2, 4, 6, 8 }; Any technical reason for this? I thought I would ask…
Joan Venge
  • 315,713
  • 212
  • 479
  • 689
15
votes
4 answers

Java: how to transform from List to Map without iterating

I have a list of objects that I need to transform to a map where the keys are a function of each element, and the values are lists of another function of each element. Effectively this is grouping the elements by a function of them. For example,…
Kkkev
  • 4,716
  • 5
  • 27
  • 43
15
votes
5 answers

Trie saves space, but how?

I am confused as to how the Trie implementation saves space & stores data in most compact form! If you look at the tree below. When you store a character at any node, you also need to store a reference to that & thus for each character of the…
Rajat Gupta
  • 25,853
  • 63
  • 179
  • 294
15
votes
1 answer

get only the first 20 items in a backbone collection

I'm trying to render only the first 20 items in a backbonejs collection. If the collection was an array I would do _.first(collection, 20). But since it's not it doesn't work. How do I limit it to 20? Thanks.
Harry
  • 52,711
  • 71
  • 177
  • 261
15
votes
6 answers

Why does Hashtable not take null key?

Why does Hashtable not take a null key? Also why does HashMap allow null keys? What is the purpose of making these two classes Key behaviour so different?
BOSS
  • 2,931
  • 8
  • 28
  • 53
15
votes
5 answers

hasattr(obj, '__iter__') vs collections

I've seen a couple posts recommending isinstance(obj, collections.Sequence) instead of hasattr(obj, '__iter__') to determine if something is a list. len(object) or hasattr(object, __iter__)? Python: check if an object is a sequence At first I was…
keegan3d
  • 10,357
  • 9
  • 53
  • 77
15
votes
4 answers

How to have 2 collections of the same type in JPA?

I've got 2 entities in JPA: Entry and Comment. Entry contains two collections of Comment objects. @Entity public class Entry { ... @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL) @IndexColumn(base = 1, name = "dnr") …
Vilmantas Baranauskas
  • 6,596
  • 3
  • 38
  • 50
15
votes
3 answers

Check if Vec contains all elements from another Vec

There is a method contains that can be used to check if a particular element exists in a Vec. How to check if all elements from a Vec are contained in another Vec? Is there something more concise than iterating manually and checking all elements…
Some Name
  • 8,555
  • 5
  • 27
  • 77
15
votes
3 answers

Is the .NET foreach statement guaranteed to iterate a collection in the same order in which it was built?

A coworker used a for loop to iterate a List in some C# code he wrote and left the comment, "did't use For Each because I wasn't sure it iterates in order. Who knows what Microsoft will do." For example, suppose we have a List built up like…
raven
  • 18,004
  • 16
  • 81
  • 112
15
votes
3 answers

how to run single request from the collection in newman

i have a collection in postman contain a lot of requests is there any option in Newman to run specific requests from this collection rather than create new folder for the specific request and run
mahmoud rabie
  • 151
  • 1
  • 4