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

VBA Adding a class to a collection

I have a class module called Holding. In it are several public variables. My code is this: Dim holdings as Collection Dim h as Holding Set holdings = new Collection For i = 1 to last Set h = new Holding h.x = y '... etc …
Logan
  • 319
  • 2
  • 6
  • 16
13
votes
3 answers

MongoDB and Nest.js: Define a custom name for a collection

I have a schema like this: @Schema() export class Pais extends Document { @Prop( raw({ codigo: { type: String, index: true, unique: true }, }), ) @Prop() descripcion: string; } …
Alex
  • 671
  • 5
  • 19
13
votes
3 answers

KeyValuePair vs. NameValueCollection

There are other questions such as KeyValuePair vs IDictionary, but I feel this one differs slightly. NameValueCollection takes a string key and string value. KeyValuePair is like a dictionary, you tell it what type the key and value is. I don't…
The Muffin Man
  • 19,585
  • 30
  • 119
  • 191
13
votes
4 answers

(Un)boxing primitive arrays in Java

in the Android Java world, is there a straighforward (ideally one-call) way to convert an array of int to an ArrayList and back? Calling toArray() on the ArrayList returns an array of Integer - not quite what I want. I can easily do that by…
Seva Alekseyev
  • 59,826
  • 25
  • 160
  • 281
13
votes
2 answers

What sorting algorithm does the .NET framework implement

Could anyone please advise when implementing something like IComparable in .NET what sorting algorithm does .NET use to actually sort the underlying data? Also is the algorithm used customizable or selectable?
Maxim Gershkovich
  • 45,951
  • 44
  • 147
  • 243
13
votes
5 answers

Get all Values from a Map for some Keys in Java/Guava?

Is there a smart way to get all Values from a Map given some Keys? I would like a method like this: public static Collection getAll(Map map, Collection keys) or is already a guava way?
FlorianOver
  • 997
  • 1
  • 7
  • 11
13
votes
5 answers

How to create a HashSet> with distinct elements?

I have a HashSet that contains multiple lists of integers - i.e. HashSet> In order to maintain uniqueness I am currently having to do two things: 1. Manually loop though existing lists, looking for duplicates using SequenceEquals. 2.…
Preets
  • 6,792
  • 12
  • 37
  • 38
13
votes
3 answers

Fastest and most efficient collection type in C#

I am building an application which will require a collection to hold about 10k of Strings. Collection will be used as queue. So was looking through different collection types in C# but could not figure out which one has best performance in regards…
Kamil Dhuleshia
  • 317
  • 2
  • 3
  • 12
13
votes
2 answers

Performance: Array.removeAll vs `= []`

Is there a difference in performance computationally and/or memory-wise between Swift Array/Dictionary primitive functions removeAll and init? Basically, I am asking, what are the pros and cons to resetting a mutable collection in Swift, and is one…
rolling_codes
  • 15,174
  • 22
  • 76
  • 112
13
votes
4 answers

When did add() method add object in collection

I have two questions. Firstly, consider the below code. public class Test{ private static final List var = new ArrayList() {{ add("A"); add("B"); System.out.println("INNER : " + var); }}; public…
RBS
  • 207
  • 1
  • 11
13
votes
4 answers

Why doesn't ConcurrentQueue.Count return 0 when IsEmpty == true?

I was reading about the new concurrent collection classes in .NET 4 on James Michael Hare's blog, and the page talking about ConcurrentQueue says: It’s still recommended, however, that for empty checks you call IsEmpty instead of comparing…
Danny Tuppeny
  • 40,147
  • 24
  • 151
  • 275
13
votes
2 answers

How to sort a collection in Magento?

I'm trying to sort a collection by attribute_id. I thought it would be easy, but I think I'm not using it correctly: $attributes = Mage::getResourceModel('eav/entity_attribute_collection') ->setOrder('attribute_id'); echo…
frinux
  • 2,052
  • 6
  • 26
  • 47
13
votes
3 answers

Preferred way to iterate a List except the first element

I often need to iterate through a List starting at the second element. For example here is a column: List column = Arrays.asList("HEADER", "value1", "value2", "value3"); I need to print only values. I see three approaches: Using…
Evgeny Kharitonov
  • 947
  • 11
  • 12
13
votes
5 answers

How do I sort a Laravel Collection by multiple properties with both asc and desc?

If I have an Illuminate\Support\Collection, how do I sort by multiple properties with both asc and desc? (This is a simple hypothetical - not at all looking for tips on query building.) $collection = User::all(); // not looking for…
Tarek Adam
  • 3,387
  • 3
  • 27
  • 52
13
votes
2 answers

Stop Hibernate from updating collections when they have not changed

I have two entity beans defined as follows (unrelated stuff removed): @Entity @Table(...) public class MasterItem implements java.io.Serializable { private Set criticalItemses = new HashSet(0); @OneToMany(fetch =…
Gordon
  • 1,210
  • 5
  • 16
  • 23