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

Sorted Map with non-unique keys

What structure to use when one needs ordering of elements by key ability to hold non-unique keys Structure struct = new Structure
EugeneP
  • 11,783
  • 32
  • 96
  • 142
14
votes
1 answer

List doesn't implements SyncRoot!

Everyone use lot of List. I need to iterate over this list, so I use the known SyncRoot pattern. Recently I noticed in this post that the SyncRoot should be avoided in favor of "embedded" thread-safety (each method will lock on an private object…
Luca
  • 11,646
  • 11
  • 70
  • 125
14
votes
2 answers

How can I define a property type as being a list (list, set, array, collection) of string in my YAML Swagger definition

I am writing a swagger definition file for an API. The API is a for a GET request /path/to/my/api: get: summary: My Custom API description: | Gets a List of FooBar IDs produces: - application/json tags: - FooBar …
Vihung
  • 12,947
  • 16
  • 64
  • 90
14
votes
1 answer

Java: CopyOnWriteArrayList vs synchronizedList

What is the difference between CopyOnWritearraylist and Collections.synchronizedList(..)? When should one be preferred over the other.
DeeEs
  • 143
  • 1
  • 4
14
votes
3 answers

Interfaces in collections framework

My question is Interface Set has method add(E e) and it extends interface Collection. Interface Collection also has method add(E e) So why do we need the same method in interface Set , since it already extends interface Collection. What is the…
Pratik Mehta
  • 345
  • 1
  • 4
  • 18
14
votes
4 answers

Inheriting List to implement collections a bad idea?

I once read an article by Imaar Spaanjars on how to build 3 tier applications. (http://imar.spaanjaars.com/416/building-layered-web-applications-with-microsoft-aspnet-20-part-1) which has formed the basis of my coding for a while now. Thus I…
shashi
  • 4,616
  • 9
  • 50
  • 77
14
votes
6 answers

Why doesn't IEnumerable implement Add(T)?

Just now find it by chance, Add(T) is defined in ICollection, instead of IEnumerable. And extension methods in Enumerable.cs don't contain Add(T), which I think is really weird. Since an object is enumerable, it must "looks like" a collection…
Cheng Chen
  • 42,509
  • 16
  • 113
  • 174
14
votes
4 answers

How to replace a value conditionally in a Collection, such as replaceIf(Predicate)?

Is there any easy way we could replace a value in a List or Collection if the value is null? We can always do list.stream().filter(Objects::nonNull); and maybe add 0 back to the list. But what I am looking for is an API like…
Raghu K Nair
  • 3,854
  • 1
  • 28
  • 45
14
votes
1 answer

What is the time complexity of constructing a PriorityQueue from a collection?

What is the complexity of Java's PriorityQueue constructor with a Collection? I used the constructor: PriorityQueue(Collection c) Is the complexity O(n) or O(n*log(n))?
Seffy Golan
  • 201
  • 3
  • 9
14
votes
6 answers

add generic Action delegates to a list

Is it possible to add a generic delegate Action to a List collection? I need some kind of simple messaging system for a Silverlight application. UPDATE The following is what i realy "want" class SomeClass { public T Data { get; set; } //…
jochen
  • 191
  • 1
  • 1
  • 4
14
votes
7 answers

HiLo generator strategy not working

I am new to hibernate. What I am trying to do is use @CollectionIdto generate an identifier for my Address class. I have used Collection interface for this. However when I use @GenericGenerator and set strategy to hilo, it throws an…
Aditya Sawant
  • 315
  • 4
  • 13
14
votes
9 answers

Why is there a List.BinarySearch(...)?

I'm looking at List and I see a BinarySearch method with a few overloads, and I can't help wondering if it makes sense at all to have a method like that in List? Why would I want to do a binary search unless the list was sorted? And if the list…
Water Cooler v2
  • 32,724
  • 54
  • 166
  • 336
14
votes
2 answers

upcast from List to List via List

I have a class A and a class B extends A In another class C I have a field private List listB; Now, for some unusual reason, I have to implement this method in C public List getList(); I tried to do so by forcing an upcast of listB field to…
Max S
  • 152
  • 1
  • 9
14
votes
3 answers

delphi Using records as key in TDictionary

Can you use a record as a Key value in TDictionary? I want to find objects based on combination of string, integer and integer. TUserParKey=record App:string; ID:integer; Nr:integer; end; ... var tmpKey:TUserParKey; …
r_j
  • 1,348
  • 15
  • 35
14
votes
6 answers

convert ArrayList.toString() back to ArrayList in one call

I have a toString() representation of an ArrayList. Copying the toString() value to clipboard, I want to copy it back into my IDE editor, and create the ArrayList instance in one line. In fact, what I'm really doing is this: my…
dotnetnewbie
  • 151
  • 1
  • 1
  • 4