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
14
votes
2 answers

Generic Test harness for java.util.Map?

I have a custom implementation of the Map interface which does some fancy stuff, like lazy evaluation of functions. the implementation should appear immutable after construction from outside (e.g. no put() and putAll() methods are supported) I it…
Andreas Petersson
  • 16,248
  • 11
  • 59
  • 91
14
votes
2 answers

How to create a XAML markup extension that returns a collection

I am using XAML serialization for an object graph (outside of WPF / Silverlight) and I am trying to create a custom markup extension that will allow a collection property to be populated using references to selected members of a collection defined…
Tim Coulter
  • 8,705
  • 11
  • 64
  • 95
14
votes
2 answers

linq how to select a parent with a child collection that contains one or many of an array (or list) of values

This seems like it would be easy enough var orx = gg.Where(x=>x.ProductAttributes.Any (pa =>pa.AttributeId == "home")); returns gg when product attributes has a value of "home" I need it to return where and gg has product attribute values from an…
jason
  • 767
  • 2
  • 9
  • 24
14
votes
4 answers

Element order in BlockingCollection<>

I have a Download Queue implemented with BlockingCollection<>. Now I want to prioritize some Download once in a while. I thought it might be great to move some elements 'up' the Collection, like in a list, but there is no method like…
14
votes
2 answers

Split up a list at each element satisfying a predicate (Scala)

In a text file I have data in the form: 1) text text 2) more text 3) even more text more even text even more text ... I read it as a list of Strings using the following: val input = io.Source.fromFile("filename.txt").getLines().toList I want to…
Luigi Plinge
  • 50,650
  • 20
  • 113
  • 180
14
votes
1 answer

What is the proper way to take an item from a BlockingCollection?

When calling BlockingCollection.Take() it is possible for the IsCompleted status of the collection to change between the check of IsCompleted and the call to Take(). The MSDN Documentation that shows an example just catches the invalid operation…
keithwill
  • 1,964
  • 1
  • 17
  • 26
14
votes
1 answer

Do C# collections always enforce order?

I.E. If I want to select from an array, is the resultant IEnumerable object necessarily in order? public class Student { public string FullName, ... } public class School { public string Name, public Student[] Students, ... } public void…
ArtOfTheSmart
  • 330
  • 2
  • 12
14
votes
3 answers

Is it valid to reduce on an empty set of sets?

Shouldn't this work? > val setOfSets = Set[Set[String]]() setOfSets: scala.collection.immutable.Set[Set[String]] = Set() > setOfSets reduce (_ union _) java.lang.UnsupportedOperationException: empty.reduceLeft at…
gladed
  • 1,705
  • 1
  • 17
  • 25
14
votes
3 answers

Convert an array to a mutable set in Scala?

How does one convert a Scala Array to a mutable.Set? It's easy to convert to an immutable.Set: Array(1, 2, 3).toSet But I can't find an obvious way to convert to a mutable.Set.
schmmd
  • 18,650
  • 16
  • 58
  • 102
14
votes
1 answer

Jackson deserialization ... Unexpected token (END_OBJECT),

I am trying to deserialize a JSON array into a Java Collection using Jackson. This motivated by the answers to this question I asked last night Can I instantiate a superclass and have a particular subclass be instantiated based on the parameters…
Ankur
  • 50,282
  • 110
  • 242
  • 312
14
votes
1 answer

Winforms binding question

I am relatively new to binding in win forms. In order to learn the subject I setup the following test application. A basic winform with a ListBox and a Button. public partial class Form1 : Form { public List stringList = new…
DoubleDunk
  • 909
  • 3
  • 11
  • 29
14
votes
10 answers

What's the role of IEnumerable and why should I use it?

Why should I use IEnumerable when I can make do with...say List? What's the advantage of the former over the latter?
Deepanjan Nag
  • 901
  • 3
  • 14
  • 26
14
votes
2 answers

Persisting & loading metadata in a backbone.js collection

I have a situation using backbone.js where I have a collection of models, and some additional information about the models. For example, imagine that I'm returning a list of amounts: they have a quantity associated with each model. Assume now that…
idbentley
  • 4,188
  • 3
  • 34
  • 50
14
votes
3 answers

Returning default list if the list is empty using java 8 Streams?

Is there any way so that the below can be performed as one set of stream operations, instead of explicitly checking if recommendedProducts is empty then return default list else return the filtered list? public List getRecommendedProducts()…
user3495691
  • 451
  • 1
  • 5
  • 16
14
votes
6 answers

Why does using different ArrayList constructors cause a different growth rate of the internal array?

I seem to stumble across something interesting in ArrayList implementation that I can't wrap my head around. Here is some code that shows what I mean: public class Sandbox { private static final VarHandle VAR_HANDLE_ARRAY_LIST; static { …
Eugene
  • 117,005
  • 15
  • 201
  • 306