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

JDK9 randomization on immutable sets and maps

Reading this question and the answer given by Eugene, I found that JDK9 immutable sets and maps will introduce a source of randomness that will affect their traversal. This means that iteration order will indeed be random, at least among different…
fps
  • 33,623
  • 8
  • 55
  • 110
15
votes
2 answers

Understanding mutable Seq

I'm pretty new to Scala and try to understand mutable Seq. Since it's in package mutable I expected there is a method that allows us to append element without copying the whole collection. But there is no += method in the mutable.Seq, but in Buffer…
St.Antario
  • 26,175
  • 41
  • 130
  • 318
15
votes
3 answers

What design pattern does Collections.sort use?

When applying a comparator to a list in the following manner, what is the design pattern being used or what is the technique being used here? Collections.sort(myCollection, new Comparator() { @Override public int compare(MyItem…
Dinesh Kumar
  • 307
  • 1
  • 3
  • 9
15
votes
3 answers

How can this function be rewritten to implement OrderedDict?

I have the following function which does a crude job of parsing an XML file into a dictionary. Unfortunately, since Python dictionaries are not ordered, I am unable to cycle through the nodes as I would like. How do I change this so it outputs an…
significance
  • 4,797
  • 8
  • 38
  • 57
15
votes
6 answers

Check if collection is empty or not

public ActionResult Create(FormCollection collection, FormCollection formValue) { try { Project project = new Project(); TryUpdateModel(project, _updateableFields); var devices = collection["devices"]; …
Prd
  • 247
  • 1
  • 2
  • 12
15
votes
4 answers

Thread-safe HashSet with Guava Collections

Like the title says, i would like to get a thread-safe HashSet using Guava Collections. Are any available?
santiagobasulto
  • 11,320
  • 11
  • 64
  • 88
15
votes
2 answers

weak warning in PyCharm: Unexpected argument

This inspection reports discrepancies between declared parameters and actual arguments, as well as incorrect arguments (e.g. duplicate named arguments) and incorrect argument order. Decorators are analyzed, too. ^That's what PyCharm is telling me.…
michen00
  • 764
  • 1
  • 8
  • 32
15
votes
3 answers

linq remove item from object array where property equals value

If i have IEnumberable list and i want to remove an item from this list based on a property of the car i want something like: list.RemoveWhere(r=>r.Year > 2000) does something like this exist ? i am doing this over and over so i want to avoid…
leora
  • 188,729
  • 360
  • 878
  • 1,366
15
votes
2 answers

I'm having problems understanding IQueryable

So I'm trying to understand IQueryable. A tutorial I'm reading suggests using it but not really sure why. The code simply returns some values using LINQ to SQL. I've done this plenty of times in the past, but not using IQueryable Why use it…
ItsPronounced
  • 5,475
  • 13
  • 47
  • 86
15
votes
3 answers

Difference between new HashMap(int) and guava Maps.newHashMapWithExpectedSize(int)

In Java, you can create a new HashMap to hold a specific number of items like so: Map m = new HashMap(100); Guava provides a Maps.newHashMapWithExpectedSize(int) method, which I would expect to simply call HashMap(int). But it doesn't do this,…
thecoop
  • 45,220
  • 19
  • 132
  • 189
15
votes
1 answer

Remove all objects from list that does not exist in another list

I have two list List> list1 = new ArrayList>(); List> list2 = new ArrayList>(); HashMap hm = new HashMap(); hm.put("1",…
Amar
  • 421
  • 1
  • 6
  • 17
15
votes
3 answers

Minimal framework in Scala for collections with inheriting return type

Suppose one wants to build a novel generic class, Novel[A]. This class will contain lots of useful methods--perhaps it is a type of collection--and therefore you want to subclass it. But you want the methods to return the type of the subclass, not…
Rex Kerr
  • 166,841
  • 26
  • 322
  • 407
15
votes
3 answers

Assembly Not Referenced compilation error in foreach loop in Razor view

EDIT: I have checked and attempted a lot of the other Assembly Not Referenced issues found on SE, but I haven't found many dealing with what should be a built-in assembly (System.Collections.Generic.List). This makes it difficult to manually add…
agc93
  • 663
  • 1
  • 7
  • 19
15
votes
3 answers

How can I have a collection of objects that differ by their associated type?

I have a program that involves examining a complex data structure to see if it has any defects. (It's quite complicated, so I'm posting example code.) All of the checks are unrelated to each other, and will all have their own modules and tests. More…
Ben S
  • 1,415
  • 3
  • 14
  • 29
15
votes
5 answers

Why setArray() method call required in CopyOnWriteArrayList

In CopyOnWriteArrayList.java, in the method set(int index, E element) below: public E set(int index, E element) { final ReentrantLock lock = this.lock; lock.lock(); try { Object[] elements = getArray(); Object oldValue =…
Pushparaj
  • 1,039
  • 1
  • 6
  • 26