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
16
votes
1 answer

Magento layered navigation on custom product collection

I have been working on a custom module for Magento (ver. 1.8.0.0) that shows a list of related products of a certain product. In order to achieve this I have created my own module by overwriting the Mage_Catalog_Block_Product_List class. Basically…
Kenny
  • 5,350
  • 7
  • 29
  • 43
16
votes
2 answers

Sort and group objects alphabetically by first letter Javascript

Im trying to create a collection like this in order to use in a react component: let data = [ { group : 'A', children : [ { name : 'Animals', id : 22 }, ... ] }, { group : 'B',…
Hesan Aminiloo
  • 418
  • 1
  • 4
  • 20
16
votes
2 answers

Why are ConcurrentSkipListSet ascending Iterators 'faster' than descending ones?

I’m using the descendingIterator method on ConcurrentSkipListSet. I’ve just checked the documentation and noticed the following comment: ‘Ascending ordered views and their iterators are faster than descending ones.’ See…
GoldenJam
  • 1,459
  • 1
  • 11
  • 17
16
votes
1 answer

Do all Lists in Java maintain insertion order

The List javadocs mentions that Lists are ordered. However, I cannot see anything specifying the nature of the ordering. Can we rely on lists e.g. ArrayList and LinkedList maintaining insertion order? I am asking about the instance where we do not…
Andy Cribbens
  • 1,370
  • 2
  • 11
  • 22
16
votes
4 answers

How to define Map contents on initialisation?

I was just wondering if it is possible to define the contents of a Map Object on initialisation. For example, an array can be created, as: new String[] {“apples”, “bananas”, “pears”} So, I was wondering if there is something similar we can do for…
Larry
  • 11,439
  • 15
  • 61
  • 84
16
votes
8 answers

Arrays.asList() doubt?

People say that asList method convert the array into list and its not copying, so every change in 'aList' will reflect into 'a'. So add new values in 'aList' is illegal, since array have fixed size. But, asList() method returns ArrayList. How the…
Manoj
  • 5,707
  • 19
  • 56
  • 86
16
votes
1 answer

Is there a foreach construct in TypeScript similar to the C# implementation?

I really like using the foreach construct for "for loops" in C#. I think it's very clean, efficient and readable. Is there a similar construct in TypeScript? For example, instead of this: setAuthorFilters(selectedAuthors) { …
user8570495
  • 1,645
  • 5
  • 19
  • 29
16
votes
1 answer

ImmutableCollections SetN implementation detail

I have sort of a hard time understanding an implementation detail from java-9 ImmutableCollections.SetN; specifically why is there a need to increase the inner array twice. Suppose you do this: Set.of(1,2,3,4) // 4 elements, but internal array is…
Eugene
  • 117,005
  • 15
  • 201
  • 306
16
votes
5 answers

invalid key in Dictionary

Why do dictionaries not just return null when an invalid key is used to index into the collection?
Saokat Ali
  • 1,055
  • 2
  • 12
  • 18
16
votes
3 answers

What collection classes to use to store long strings?

I will be getting a JSON string every .01 seconds or even faster and I have to insert it in some collection so that I can later loop through every row and do some processing and delete that row after that. The process of insertion keeps on going. I…
user1254053
  • 755
  • 3
  • 19
  • 55
16
votes
1 answer

VueJS - How to make models and collections?

I am attempting to learn VueJS and I'm finding it hard to understand how to make models and collections. For example, I want to have a collection (or list) of Employees and each Employee is a model. But I'm not sure how to accomplish this in…
zardon
  • 1,601
  • 4
  • 23
  • 46
16
votes
3 answers

Java addAll(collection) vs new ArrayList(collection)

Why do i get different behaviors with: Collection col2 = new ArrayList(col); Collection col2 = new ArrayList(); col2.addAll(col) I'm working with viewers, and the code is complex, and i'm trying to explain the "root" of the problem. Another…
marcolopes
  • 9,232
  • 14
  • 54
  • 65
16
votes
2 answers

Recursively Get Properties & Child Properties Of An Object

Ok so at first I thought this was easy enough, and maybe it is and I'm just too tired - but here's what I'm trying to do. Say I have the following objects: public class Container { public string Name { get; set; } public List
Wayne
  • 185
  • 1
  • 1
  • 9
16
votes
3 answers

Eloquent collections methods such as only or except return an empty collection

From the docs, I have tested the following example with the ->only() method $collection = collect(['product_id' => 1, 'name' => 'Desk', 'price' => 100, 'discount' => false]); $filtered = $collection->only(['product_id',…
Pathros
  • 10,042
  • 20
  • 90
  • 156
16
votes
13 answers

How to compare two Collections for "equivalence" based on fields from different Java classes?

Given any two classes, e.g. ClassA and ClassB below: class ClassA { private int intA; private String strA; private boolean boolA; // Constructor public ClassA (int intA, String strA, boolean boolA) { this.intA = intA;…
Steve Chambers
  • 37,270
  • 24
  • 156
  • 208