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

ASP.NET MVC Editing A Collection Best Practices - Your Opinion

Given the following class, what is your opinion on the best way to handle create/edit where Attributes.Count can be any number. public class Product { public int Id {get;set;} public string Name {get;set;} public IList Attributes…
Kyle West
  • 8,934
  • 13
  • 65
  • 97
13
votes
8 answers

Perform operation on n random distinct elements from Collection using Streams API

I'm attempting to retrieve n unique random elements for further processing from a Collection using the Streams API in Java 8, however, without much or any luck. More precisely I'd want something like this: Set subList = new…
habitats
  • 2,203
  • 2
  • 23
  • 31
13
votes
2 answers

Java, ConcurrentLinkedDeque vs ConcurrentLinkedQueue - the difference?

Api links for ConcurrentLinkedDeque and ConcurrentLinkedQueue: http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ConcurrentLinkedDeque.html http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ConcurrentLinkedQueue.html What is…
mjs
  • 21,431
  • 31
  • 118
  • 200
13
votes
2 answers

In C#, what is the best way to group consecutive dates in a list?

I have a list of dates and I want to group by items that are consecutive days so if in the list I have the following dates: Dec 31, 2013 Jan 1, 2014 Jan 2, 2014 Feb 1, 2014 Feb 2, 2014 Feb 16, 2014 Mar 13, 2014 I want to come up with a way to…
leora
  • 188,729
  • 360
  • 878
  • 1,366
13
votes
5 answers

Type-safe, generic, empty Collections with static generics

I return empty collections vs. null whenever possible. I switch between two methods for doing so using java.util.Collections: return Collections.EMPTY_LIST; return Collections.emptyList(); where emptyList() is supposed to be type-safe. But I…
Droo
  • 3,177
  • 4
  • 22
  • 26
13
votes
2 answers

How to create a collection automatically in mongoDB if it's not already there?

I am creating passport authentication for node using mongoose. I don't have any collection called "users" in my database. But while creating new user using the schema like below var mongoose = require('mongoose'); module.exports =…
Purva chutke
  • 131
  • 1
  • 1
  • 3
13
votes
2 answers

Creating a defaultdict with empty numpy array

I'm wondering if there's a more clever way to create a default dict from collections. The dict should have an empty numpy ndarray as default value. My best result is so far: import collections d = collections.defaultdict(lambda:…
zinjaai
  • 2,345
  • 1
  • 17
  • 29
13
votes
1 answer

Convert Set to Collection
I have a Set. I need to get a Collection from it. I can think of making a for loop to add and cast all the Objects, but that is ugly and probably also slow. @Override public Collection keys() { // props is based on…
MightyPork
  • 18,270
  • 10
  • 79
  • 133
13
votes
1 answer

Paging over a lazy-loaded collection with NHibernate

I read this article where Ayende states NHibernate can (compared to EF 4): Collection with lazy=”extra” – Lazy extra means that NHibernate adapts to the operations that you might run on top of your collections. That means that…
moribvndvs
  • 42,191
  • 11
  • 135
  • 149
13
votes
2 answers

When Iterating Over ConcurrentDictionary and only reading, is ConcurrentDictionary locked?

I have a ConcurrrentDictionary created as an application object in my web app. and it is shared among sessions. (Basically serves as a repository.) At times a new item is added to the dictionary by any available session. Allow Admin View…
raddevus
  • 8,142
  • 7
  • 66
  • 87
13
votes
2 answers

How to sort ArrayList using Comparator?

I have a Class Student that Implements a static method public static Comparator getCompByName() that returns a new comparator object for Student that compares 2 Students objects by the attribute 'name'. I need to now test this by sorting…
Reeggiie
  • 782
  • 7
  • 16
  • 36
13
votes
8 answers

A TreeSet or TreeMap that allow duplicates

I need a Collection that sorts the element, but does not removes the duplicates. I have gone for a TreeSet, since TreeSet actually adds the values to a backed TreeMap: public boolean add(E e) { return m.put(e, PRESENT)==null; } And the TreeMap…
Zeeshan
  • 11,851
  • 21
  • 73
  • 98
13
votes
4 answers

CollectionChanged and IList of Items - why the difficulties

I am looking into the topic why a ObservableCollection/ListCollectionView/CollectionView raises a NotSuportedException when calling the CollectionChanged with the parameter of IList. //Throws an exception private void collectionChanged_Removed(IList…
13
votes
5 answers

Generic method arguments - Java

I have two almost identical methods, but I'm trying to avoid code duplication. Each of them takes a unique object as arguments and finds out the highest value from it. Here's an example: public Integer getHighestIndexValue(List list) { …
yonikawa
  • 581
  • 1
  • 9
  • 32