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
4 answers

Why doesn't C# LinkedList.RemoveFirst() return the removed value?

Is there some idiomatic, performance or design philosophy reason why C#'s LinkedList's RemoveFirst() and RemoveLast() operations don't return the value removed? Right now, if I want to read and remove the first value, I believe the incantation…
Dilum Ranatunga
  • 13,254
  • 3
  • 41
  • 52
15
votes
4 answers

backbone.js collection get vars

This seems like an obvious one, but I'm somehow missing it... How do you send options along with a backbone.js collection fetch()? Or, from a broader point of view: I have a large dataset on the server, messages in this case, that I want to make…
nicholas
  • 14,184
  • 22
  • 82
  • 138
15
votes
3 answers

How to create no-duplicates ConcurrentQueue?

I need a concurrent collection that doesn't allow duplicates (to use in BlockingCollection as Producer/Consumer). I don't need strict order of elements. From another hand i want to minimize the maximum time of element "live" in collection. I.e.…
Oleg Vazhnev
  • 23,239
  • 54
  • 171
  • 305
15
votes
8 answers

Difference between Map.put and Map.putAll methods?

Map.putAll is equivalent to that of calling Map.put(k, v) on the map once for each mapping from key k to value v in the specified map. So with the functional aspect, both are same. So, I am curious to know what are the other differences and when…
GuruKulki
  • 25,776
  • 50
  • 140
  • 201
15
votes
2 answers

Java 8 Map merge VS compute, essential difference?

It seems Both merge and compute Map methods are created to reduce if("~key exists here~") when put. My problem is: add to map a [key, value] pair when I know nothing: neither key existing in map nor it exist but has value nor value == null nor key…
J.J. Beam
  • 2,612
  • 2
  • 26
  • 55
15
votes
6 answers

.net collection for fast insert/delete

I need to maintain a roster of connected clients that are very shortlived and frequently go up and down. Due to the potential number of clients I need a collection that supports fast insert/delete. Suggestions?
spender
  • 117,338
  • 33
  • 229
  • 351
15
votes
3 answers

Java Comparator for byte array (lexicographic)

I have a hashmap with byte[] keys. I'd like to sort it through a TreeMap. What is the most effective way to implement the comparator for lexicographic order?
marcorossi
  • 1,941
  • 2
  • 21
  • 34
15
votes
4 answers

add a list in a hashset using addAll

In java i m not able to add a list to a hashset using hash set addAll method List a = new ArrayList(); a.add(20); List b = new ArrayList(); b.add(30); Set set = new HashSet ( a ); set.addAll( b); Please help Thanks
Pradyut Bhattacharya
  • 5,440
  • 13
  • 53
  • 83
15
votes
2 answers

Why does count return different types for Collection vs. Array?

When I'm extending Collection the type of count is IndexDistance. When I'm extending Array type the count is of type Int Why is there such a distinction? Is this a recent change or it's always been like this? I've read this answer but couldn't pick…
mfaani
  • 33,269
  • 19
  • 164
  • 293
15
votes
2 answers

Is there any way to efficiently reconstruct a collection based on a sequence of inserts/removals?

Note: the below code happens to be C#, but really an answer in any language would be helpful for me. Suppose rather than an actual collection (e.g., a List), I have a sequence of operations, each looking something like this: struct…
Dan Tao
  • 125,917
  • 54
  • 300
  • 447
15
votes
6 answers

Are they any decent on-disk implementations of Java's Map?

I'm looking for an on-disk implementation of java.util.Map. Nothing too fancy, just something that I can point at a directory or file and have it store its contents there, in some way it chooses. Does anyone know of such a thing?
jjujuma
  • 22,055
  • 12
  • 44
  • 46
15
votes
1 answer

Weird problem when binding a dynamic list

INITIAL QUESTION (UPDATED BELOW) I'm using an AutoPopulatingList list to instatiate an object invoking a constructor with some parameters. Something like the code below. I had used it before without any problems but I can't get it working…
Javi
  • 19,387
  • 30
  • 102
  • 135
15
votes
1 answer

Select property from each object in a list

Say I have a List, where the first element in each is a string. Is there an extension function in Kotlin to select the first element from each of these tuples? I'm looking for something like the C# LINQ syntax for Select: myTuples.Select(t =>…
Nate Jenson
  • 2,664
  • 1
  • 25
  • 34
15
votes
6 answers

Java collections. Why no Primitive Types?

Possible Duplicate: storing primitive values in a java collection? My Java textbook says elements of a collection, for example ArrayList, cannot be primitive types. Is there a reason for this? I mean did someone at Sun decide on this or is there…
user485498
15
votes
3 answers

OOP: Difference between ArrayList al = new ArrayList() and List al = new ArrayList()?

Possible Duplicate: List versus ArrayList Difference between ArrayList al = new ArrayList() and List al = new ArrayList() ?
Hari kanna
  • 2,461
  • 6
  • 29
  • 43