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

In what conditions does powershell unroll items in the pipeline?

Consider the following: function OutputArray{ $l = @(,(10,20)) $l } (OutputArray) -is [collections.ienumerable] # C:\ PS> True (OutputArray).Count # C:\ PS> 2 $l is "unrolled" when it enters the pipeline. This answer states that…
alx9r
  • 3,675
  • 4
  • 26
  • 55
15
votes
5 answers

executeFetchRequest throw fatal error: NSArray element failed to match the Swift Array Element type

I'm testing swift with CoreData and I created the following code: import UIKit import CoreData class Contact: NSManagedObject { @NSManaged var name: String @NSManaged var email: String class func execute(){ let…
Sebastian
  • 6,154
  • 5
  • 33
  • 51
15
votes
3 answers

Check if a key exists in play.api.libs.json.Json

contains like functionality for play.api.libs.json.Json val data=Map("id" -> "240190", "password" -> "password","email" -> "email@domain.com") data.contains("email")//true val info=Json.obj("id" -> "240190", "password" -> "password","email" ->…
Govind Singh
  • 15,282
  • 14
  • 72
  • 106
15
votes
5 answers

How to use java.Set

I'm trying to make it working for quite some time,but just can't seem to get it. I have object Tower built of Block's. I've already made it working using arrays, but I wanted to learn Set's. I'd like to get similar functionality to this: public…
sasklacz
  • 3,610
  • 10
  • 39
  • 58
15
votes
8 answers

Is it possible to get the SQL alias of a join table for a Hibernate sqlRestriction?

I have a Person class which has a String collection of aliases representing additional names that person may go by. For example, Clark Kent may have aliases "Superman" and "Man of Steel". Dwight Howard also has an alias of…
Jason Novak
  • 1,081
  • 3
  • 13
  • 26
15
votes
4 answers

Efficient algorithm for detecting different elements in a collection

Imagine you have a set of five elements (A-E) with some numeric values of a measured property (several observations for each element, for example "heart rate"): A = {100, 110, 120, 130} B = {110, 100, 110, 120, 90} C = { 90, 110, 120, 100} D = {120,…
Guido
  • 46,642
  • 28
  • 120
  • 174
15
votes
3 answers

Changing order of ordered dictionary in python

I have an ordered dictionary and want to change the individual order. In the below code example I want to item 3 (people), along with its values, to move to position 2. So the order will be animals, people, food, drinks. How do I go about…
speedyrazor
  • 3,127
  • 7
  • 33
  • 51
15
votes
6 answers

Print all key/value pairs in a Java ConcurrentHashMap

I am trying to simply print all key/value pair(s) in a ConcurrentHashMap. I found this code online that I thought would do it, but it seems to be getting information about the buckets/hashcode. Actually to be honest the output it quite strange, its…
DanGordon
  • 671
  • 3
  • 8
  • 26
15
votes
4 answers

Generic Map of Generic key/values with related types

I'm trying to create a generic type that keeps a map of the versions of itself that have been created for later use. Effectively, it's an singleton pattern where there's one instance per type. The code I have so far is: public class FieldBinder
RHSeeger
  • 16,034
  • 7
  • 51
  • 41
15
votes
4 answers

Unique List in .NET 2

What is a preferably generic; unique(IComparable/IEquitable) valued collection of objects for .NET 2? (à la List, or an equivalent of HashSet from .NET 3.5, but without ordered items)
serhio
  • 28,010
  • 62
  • 221
  • 374
15
votes
9 answers

Why not allow an external interface to provide hashCode/equals for a HashMap?

With a TreeMap it's trivial to provide a custom Comparator, thus overriding the semantics provided by Comparable objects added to the map. HashMaps however cannot be controlled in this manner; the functions providing hash values and equality checks…
volley
  • 6,651
  • 1
  • 27
  • 28
15
votes
4 answers

Why is there a method iterator() on java.util.Collection

Why is there the method iterator() defined on the interface java.util.Collection when it already extends java.util.Iterable which has this very method defined. I'm thinking some sort of backward compatability or an opportunity to write some JavaDoc…
Dan
  • 9,681
  • 14
  • 55
  • 70
15
votes
9 answers

What collection to use instead of 2D array in Java?

I want to use a collection in place of 2D array so that I don't need to give its size at the time of declaration and I can add as many elements as I want dynamically.
Amit
  • 33,847
  • 91
  • 226
  • 299
15
votes
3 answers

Fast way to check if IEnumerable contains no duplicates (= is distinct)

Is there a fast built-in way to check if an IEnumerable contains only distinct strings? In the beginning I started with: var enumAsArray = enum.ToArray(); if (enumAsArray.Length != enumAsArray.Distinct().Count()) throw ... However, this…
D.R.
  • 20,268
  • 21
  • 102
  • 205
15
votes
4 answers

java.util.ConcurrentModificationException in Non Multithreaded Program

Hey SO Guru's im having one heck of a job with this code public void kill(double GrowthRate, int Death) { int before = population.size(); for (PopulationMember p : population) { int[] probs =…
Gwilym
  • 775
  • 2
  • 9
  • 19