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

Ordering of elements in Java HashSet

Why do the second and third sets preserve order: Integer[] j = new Integer[]{3,4,5,6,7,8,9}; LinkedHashSet i = new LinkedHashSet(); Collections.addAll(i,j); System.out.println(i); HashSet hi = new…
Sam Adamsh
  • 3,331
  • 8
  • 32
  • 53
12
votes
2 answers

How do I search for elements whose collection contains another element in Grails?

Let's say I have a domain class called "User" which can follow other "User" objects. It does so having a field specified as: def hasMany=[followedUsers:User] I need to do the reverse (find all User objects that follow a specific User object)…
ArmlessJohn
  • 305
  • 4
  • 11
12
votes
6 answers

Magento get all products

I am trying to get the entire magento product collection, without any filters or restrictions, but I fail to get all products. I've tried various methods already, but they all give me a very limited selection of products. Let's say the store…
JNDPNT
  • 7,445
  • 2
  • 34
  • 40
12
votes
8 answers

.NET Dictionary vs Class Properties

Coming from a javascript background, collections like dictionaries are often implemented as objects because their properties can be referenced by association: // js example var myDict = { key1 : "value1", key2 : "value2" }; myDict.key1; //…
Daniel Szabo
  • 7,181
  • 6
  • 48
  • 65
12
votes
3 answers

C# Object reference not set to an instance of an object. Instantiating Class within a List?

public class OrderItem { public string ProductName { get; private set; } public decimal LatestPrice { get; private set; } public int Quantity { get; private set; } public decimal TotalOrder { get {return LatestPrice * Quantity;}} …
Taemint
  • 141
  • 1
  • 1
  • 6
12
votes
5 answers

what's the usage of the code in the implementation of AbstractCollection's toArray Method

public Object[] toArray() { // Estimate size of array; be prepared to see more or fewer elements Object[] r = new Object[size()]; Iterator it = iterator(); for (int i = 0; i < r.length; i++) { if (! it.hasNext()) // fewer…
ChandlerSong
  • 387
  • 1
  • 14
12
votes
2 answers

How to present a Collection of (View)Models in a ViewModel

I have a question regarding the MVVM design for C#/WPF. I've had a look at several demo applications, but they didn't really handle my problem. My application consists of objects that contain other objects. Much like in a parent - children…
Torsten
  • 1,696
  • 2
  • 21
  • 42
12
votes
7 answers

Remove all All Elements not working

I noticed this function in a .NET project I am working on. private static void RemoveAllElements(ref List listToBeRemoved) { foreach (var i in listToBeRemoved) { listToBeRemoved.Remove(i); } } Is…
abhi
  • 3,082
  • 6
  • 47
  • 73
12
votes
1 answer

What is the basic collection type in Scala?

Or in other words what is the equivalent of C# IEnumerable in Scala? I thought it is Seq[T], but I already found out, that HashMap does not implement this, so it cannot be true. So, what is it?
greenoldman
  • 16,895
  • 26
  • 119
  • 185
12
votes
5 answers

Ruby Rails collection select is displaying blank "prompt" value?

I have a collection select like the following: <%= f.collection_select :region_id, Region.find(:all), :id, :name, { :prompt => 'Select a State/Province' }, :style => "width: 200px;" %> Sometimes the prompt from the :prompt option appears, but…
Tony
  • 18,776
  • 31
  • 129
  • 193
12
votes
4 answers

What sort does Java Collections.sort(nodes) use?

I think it is MergeSort, which is O(n log n). However, the following output…
Kyle Jones
  • 621
  • 2
  • 8
  • 15
12
votes
3 answers

Angular 14: Error: A collection and schematic is required during execution

I am trying to learn angular. I installed the lastest version and created an app called test using ng new test command. Then I opened the app in visual studio code. In the terminal I entered the following command to create a new component: ng g…
Nazir
  • 155
  • 1
  • 2
  • 7
12
votes
7 answers

Is there an ImmutableBitSet in Java?

Is there any Java library offering an ImmutableBitSet? I didn't find any, neither Guava nor using Google.
maaartinus
  • 44,714
  • 32
  • 161
  • 320
12
votes
5 answers

CollectionViewSource Filter not refreshed when Source is changed

I have a WPF ListView bound to a CollectionViewSource. The source of that is bound to a property, which can change if the user selects an option. When the list view source is updated due to a property changed event, everything updates correctly, but…
Steve
  • 4,859
  • 5
  • 21
  • 17
12
votes
3 answers

Are Scala parallel collections better in some ways than the parallel collections already available in Java?

I've recently been learning about various libraries for concurrency in Java such as ConcurrentHashMap and the lovely non blocking one from Cliff Click I don't know much about Scala but I've heard good things about the recent parallel collections…
barrymac
  • 2,750
  • 1
  • 20
  • 32
1 2 3
99
100