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

Java TreeSet: remove and contains() not working

I have added some simple objects to a TreeSet, but when I call the TreeSet's remove() and contains() methods, they don't work. However, when I iterate over the set the object is printed. Employee objects shall be added to the set while the objects…
user1812379
  • 827
  • 3
  • 11
  • 22
14
votes
2 answers

How would I know if a property is a generic collection

I need to know if the type of a property in a class is a generic collection (List, ObservableCollection) using the PropertyInfo class. foreach (PropertyInfo p in (o.GetType()).GetProperties()) { if(p is Collection ????? ) }
Lance
  • 2,774
  • 4
  • 37
  • 57
14
votes
1 answer

Unexpected complexity of common methods (size) in Java Collections Framework?

Recently, I've been surprised by the fact that some Java collections don't have constant time operation of method size(). While I learned that concurrent implementations of collections made some compromises as a tradeoff for gain in concurrency…
mario
  • 191
  • 1
  • 6
14
votes
4 answers

Java generics warnings on java.util.Collections

I have a method: public List sortStuff(List toSort) { java.util.Collections.sort(toSort); return toSort; } This produces a warning: Type safety: Unchecked invocation sort(List) of the generic method sort(List) of…
IAmYourFaja
  • 55,468
  • 181
  • 466
  • 756
14
votes
1 answer

Is there a way to check if an item exists in a Python tuple?

I have seen an index function but it says it errors out if it can't find it. Is there a simple way to just check if the item exists? I just want to get a boolean value of the result so like: if tuple.exists("item"): print "it exists"
Joan Venge
  • 315,713
  • 212
  • 479
  • 689
14
votes
1 answer

LINQ gets confused when implementing IEnumerable twice

My class implements IEnumerable twice. How can I get LINQ to work without casting hashtable every time? I wrote my own covariant hashtable implementation that also inherits from .NET's IDictionary. Ultimately, it implements…
Daniel A.A. Pelsmaeker
  • 47,471
  • 20
  • 111
  • 157
14
votes
3 answers

letting a java function accept a collection or an array

I am trying to write a function that takes some strings and does something with them. The only thing I'm going to do that the set of strings is loop over them. Right now I end up with an awkward construct along the lines of public void…
BostonJohn
  • 2,631
  • 2
  • 26
  • 48
14
votes
4 answers

Remove elements from Dictionary

I have a Dictionary, where items are (for example): "A", 4 "B", 44 "bye", 56 "C", 99 "D", 46 "6672", 0 And I have a List: "A" "C" "D" I want to remove from my dictionary all the elements whose keys are not in my list, and at the end my…
Nick
  • 10,309
  • 21
  • 97
  • 201
14
votes
4 answers

How can I do a conditional collectEntries in groovy

Is it possible to do a conditional collectEntries like collect ?
Thermech
  • 4,371
  • 2
  • 39
  • 60
14
votes
4 answers

dequeueReusableCellWithReuseIdentifier crash 'could not dequeue a view of kind" UICollectionElementKindCell'

I am getting the following crash: Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier Cell - must register a nib or a class for the…
Ken Roy
  • 915
  • 1
  • 10
  • 15
14
votes
3 answers

.NET equivalent of Java's List.subList()?

Is there a .NET equivalent of Java's List.subList() that works on IList?
ripper234
  • 222,824
  • 274
  • 634
  • 905
14
votes
2 answers

Where can I find an implementation of Java EL 3.0

The Expression Language version 3.0 is currently being designed. It adds various cool features like mapping and filtering collections by a lambda expression. Spring EL has a comparable feature which does not use lambdas though. Despite googling for…
Saintali
  • 4,482
  • 2
  • 29
  • 49
14
votes
6 answers

Dictionary where the key is a pair of integers

I need to use a Dictionary, where TKey is a pair of ints. I thought of using KeyValuePair for the type of my keys and I was wondering if this was the best way around. I'm also curious to know if the Dictionary will create separate entries for two…
user356178
14
votes
5 answers

Need a Java map/table with multiple keys to one value. Value is commonly altered

What I need is a collection which allows multiple keys to access a single object. I need to apply frequent alterations to this object. It also must be efficient for 500k+ entries.
Duncan
  • 1,758
  • 6
  • 21
  • 34
14
votes
2 answers

Java partially ordered Collection

I am looking for a Java implementation of a data structure which holds a collection of elements for which a partial ordering is defined, and which allows one to iterate over those elements in some topological order (any of the possible orderings is…
JimN
  • 3,120
  • 22
  • 35