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

How and where to modify Magento search query?

First of all, I found similar questions in SO but there is not any answer for them. So, the first part of the question is a little bit duplicated. I want to improve search results in Magento. Here is what I've done already: 1. Search with AND…
enenen
  • 1,967
  • 2
  • 17
  • 33
13
votes
2 answers

null-safe Collection contains method

What's the best way to do null-safe contains on a Java collection? in other words - if (collection != null && collection.contains(x)) ? I was hoping Apache commons-collections had something like CollectionUtils.contains(collection, x) that…
wrschneider
  • 17,913
  • 16
  • 96
  • 176
13
votes
2 answers

Using a Hashtable to store only keys?

Possible Duplicate: Which collection for storing unique strings? I am currently using a Dictionary to store a list of unique identifiers. These identifiers do not need to have any data associated with them - I am just using the…
We Are All Monica
  • 13,000
  • 8
  • 46
  • 72
13
votes
4 answers

Sort a list with SQL or as a collection?

I have some entries with dates in my database. What is best?: Fetch them with a sql statement and also apply order by. Get the list with sql, and order them within the application with collection.sort or so? Thanks
membersound
  • 81,582
  • 193
  • 585
  • 1,120
13
votes
1 answer

hashCode and equals for Collections.unmodifiableCollection()

The Collections class has a number of static helper methods to provide read-only views of various collection types, such as unmodifiableSet(), unmodifiableList(), etc. For these view objects, the hashCode() and equals() methods forward calls to the…
mergeconflict
  • 8,156
  • 34
  • 63
13
votes
5 answers

Collection removeAll ignoring case?

Ok so here is my issue. I have to HashSet's, I use the removeAll method to delete values that exist in one set from the other. Prior to calling the method, I obviously add the values to the Sets. I call .toUpperCase() on each String before adding…
user84786
  • 631
  • 7
  • 19
  • 33
13
votes
5 answers

How do i keep a hashset alphabetically ordered?

I have a collection of a big number of objects that are defined by name/value pairs. I need to have fast access to any of their values and to be able to return them ordered alphabetically by name. First I thought I might use a HashMap to get fast…
svz
  • 4,516
  • 11
  • 40
  • 66
13
votes
4 answers

remove html node from htmldocument :HTMLAgilityPack

In my code, I want to remove the img tag which doesn't have src value. I am using HTMLAgilitypack's HtmlDocument object. I am finding the img which doesn't have src value and trying to remove it.. but it gives me error Collection was…
Priya
  • 1,375
  • 8
  • 21
  • 45
13
votes
5 answers

Do we have some sort of a Triple collection in C#

I was thinking of keeping three pieces of information for each object of a list. So I can create a class with three properties for those three pieces of information, and then create a Collection of that class type... But I was wondering in .NET 3.5…
Bohn
  • 26,091
  • 61
  • 167
  • 254
13
votes
3 answers

What is alternative hashing for String keys in Java 8?

Java 8 is providing alternative hashing for String keys to improve performance when a large number of key hash code collisions are encountered. Can anybody explain what is that and how it will work?
Pramod Kumar
  • 7,914
  • 5
  • 28
  • 37
13
votes
4 answers

Do .NET design guidelines suggest returning List over IEnumerable?

Context: I sent an email to my colleagues telling them about Enumerable.Empty() as a way to return empty collections without doing something like return new List(); I got a reply saying that the downside is that it doesn't expose a specific…
Tesserex
  • 17,166
  • 5
  • 66
  • 106
13
votes
3 answers

Is it Possible to create a Queue for HashMap set?

Right now I am trying to create a producer/consumer thread, the producer thread goes through all possible combinations of letters and creates their respective MD5 hashes. Then each combination and its hash is put into the HashMap. Now…
David Kroukamp
  • 36,155
  • 13
  • 81
  • 138
13
votes
1 answer

(Linked)BlockingQueue.put(null) throws NullPointerException

I have checked the implementation, it does so intentionally public void put(E e) throws InterruptedException { if (e == null) throw new NullPointerException(); This surprise is not convenient for user (who wants to signal end of stream this…
Val
  • 1
  • 8
  • 40
  • 64
13
votes
1 answer

ArgMin for vector in C++?

I'd like to find the index of the minimum value in a C++ std::vector. Here's a somewhat verbose implementation of this: //find index of smallest value in the vector int argMin(std::vector vec) { std::vector::iterator mins…
solvingPuzzles
  • 8,541
  • 16
  • 69
  • 112
12
votes
6 answers

Is Collections.shuffle() really random enough? Practical examples seem to deny this statement

I have 1000 unique objects in a java.util.List, each referring to an image, each image in the 1000-list is unique and now I'd like to shuffle them, so that I can use the first 20 objects and present them to the website-user. The user can then click…
basZero
  • 4,129
  • 9
  • 51
  • 89