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
15
votes
5 answers

C# AppSettings: Is there a easy way to put a collection into

i tried and System.Configuration.ConfigurationManager.AppSettings.GetValues("List"); But i only get the last member…
Markus
  • 1,465
  • 4
  • 18
  • 29
15
votes
3 answers

Java 8: HashMap initialization with lambda expressions

I'm trying to declare and define larger hash map at once. This is how I do it: public HashMap> opcode_only = new HashMap>() {{ put(x, y); put(x, y); }}; But, when I try to use lambda…
user35443
  • 6,309
  • 12
  • 52
  • 75
15
votes
1 answer

backbone.js iterate a collection

I have set up a collection for Logs. The api returns the results as JSON. I saw a previous topic where it was suggested to add the parse method on the collection. Having done so, when I execute the code I am not getting any output to the console.…
porterhaus
  • 439
  • 2
  • 5
  • 17
15
votes
4 answers

How to concurrently process elements in a Collection in Java

I need to process elements in some Collection instance concurrently. In other words instead of iterating a Collection instance for (Someclass elem : coll){ process(elem); } I’d like to process those elements concurrently. Say, something like…
serg kunz
  • 505
  • 1
  • 4
  • 9
15
votes
4 answers

Updating of BindingSource in WinForms does not update Datasource Collection

I want to display a custom collection in a DataGridView in a Windows Forms app. This custom collection implements ICollection, and IEnumerable. I have set up a BindingSource, using the collection as the .DataSource property. The DataGridView is…
Jeff Clare
  • 185
  • 1
  • 1
  • 8
15
votes
3 answers

How to sort Arraylist of objects

I have ArrayList, which containst football teams (class Team). Teams have points and i want to sort them by number of points. public class Team { private int points; private String name; public Team(String n) { name =…
n0hepe
  • 188
  • 1
  • 2
  • 11
15
votes
2 answers

UnsupportedOperationException - the removeAll method is not supported by this collection (Java Collections)

Set availableBadges = myService.getAvailableBadges(); List allBadges = Arrays.asList(Badge.values()); allBadges.removeAll(availableBadges); /* Badge is an enumn */ what collections do support remove all ?
NimChimpsky
  • 46,453
  • 60
  • 198
  • 311
15
votes
3 answers

Redundant implementation of List interface in ArrayList.java

Possible Duplicate: Why does ArrayList have “implements List”? I am new to java I was trying to see the hierarchy of collection interface. I found that the signature of AbstractList.java is like public abstract class AbstractList extends…
user1918715
15
votes
5 answers

Java 7 API design best practice - return Array or return Collection

I know this question has be asked before generic comes out. Array does win out a bit given Array enforces the return type, it's more type-safe. But now, with latest JDK 7, every time when I design this type of APIs: public String[]…
Shengjie
  • 12,336
  • 29
  • 98
  • 139
15
votes
7 answers

How should I use properties when dealing with read-only List members

When I want to make a value type read-only outside of my class I do this: public class myClassInt { private int m_i; public int i { get { return m_i; } } public myClassInt(int i) { m_i = i; } } What can I do…
George
  • 15,241
  • 22
  • 66
  • 83
15
votes
1 answer

VBA: Iteration speed of variant array vs. typed array vs. non-keyed collection

My project requires a bunch of dynamically-resizable arrays for different objects. An array may hold any number of objects, potentially thousands, of a single class, but not objects of multiple classes. Mostly I will be iterating through arrays,…
Swiftslide
  • 1,307
  • 7
  • 23
  • 34
15
votes
4 answers

Any Intersection in Two Collections

i have to find out whether or not two collections have any intersection, the way that i did that is using LINQ's "Join" to get the Intersection of the two collections and then i use "Any". But i wonder, is there other more "elegant" way of doing…
Bongo Sharp
  • 9,450
  • 8
  • 25
  • 35
14
votes
1 answer

Asserting in NUnit that a collection is in the same order as an expected collection

I know how to check that a collection is ordered by some property: Assert.That(actual, Is.Ordered.By("Foo")); How can I assert that actual contains the elements (1,2,5,3,4) in this specific order (without writing a custom comparer).
ripper234
  • 222,824
  • 274
  • 634
  • 905
14
votes
5 answers

Efficiently deleting item from within 'foreach'

For now, the best I could think of is: bool oneMoreTime = true; while (oneMoreTime) { ItemType toDelete=null; oneMoreTime=false; foreach (ItemType item in collection) { if (ShouldBeDeleted(item)) { …
Daniel Mošmondor
  • 19,718
  • 12
  • 58
  • 99
14
votes
17 answers

Optimized implementations of java.util.Map and java.util.Set?

I am writing an application where memory, and to a lesser extent speed, are vital. I have found from profiling that I spend a great deal of time in Map and Set operations. While I look at ways to call these methods less, I am wondering whether…
Sean Owen
  • 66,182
  • 23
  • 141
  • 173