Questions tagged [generic-collections]

A collection that supports generic typing of its elements

Since java 1.5 (released in 2004), the JDK java.util.Collection interface is generic (typed).

Unless you're using an ancient version of java, the word "generic" in "generic collections" is redundant.

390 questions
12
votes
4 answers

Limit the size of a generic collection?

Is there any way to limit the size of a generic collection? I have a Stack of WriteableBitmap which I am using to store a clone of a WriteableBitmap on each change, meaning that I can undo easily by simply Popping the most recent WriteableBitmap off…
JMK
  • 27,273
  • 52
  • 163
  • 280
11
votes
3 answers

Generic Container in C++

I'm attempting to create a generic container type to provide a single common interface, as well as hide the internal containers I'm using as they are subject to change. Basically I have plugins that return collections of items and I don't wish the…
Ben Crowhurst
  • 8,204
  • 6
  • 48
  • 78
11
votes
2 answers

How to inherit from TObjectList instead of inheriting from TObjectList

Why does this program report memory leaks? {$APPTYPE CONSOLE} uses System.Generics.Collections; type TDerivedGenericObjectList = class(TObjectList) public constructor Create; end; constructor…
alondono
  • 2,496
  • 2
  • 28
  • 34
11
votes
8 answers

Multi-key DataStructure

I'm looking for a data structure that I can search with multiple keys. Easier to explain with an example: var myDataStructure = new MultiKeyDataStructure(); myDataStructure.Add(1, "some string 1", new…
ConditionRacer
  • 4,418
  • 6
  • 45
  • 67
10
votes
3 answers

Convert Dictionary into structured format string

I have a Dictionary object declared as var as Dictionary(of String, String). I am trying to utilize the LINQ extensions available to the Generic Collection but am only getting the non-extension methods. I need to turn the Dictionary collection into…
GoldBishop
  • 2,820
  • 4
  • 47
  • 82
9
votes
6 answers

Is there a generic collection with a key/value pair where key can occur more than once?

I want to use a generic collection like Dictionary, but Dictionary requires that every key be unique. I have multiple values for the same "key", so I need a generic collection that will allow for that. I realize that this makes the key no longer…
richard
  • 12,263
  • 23
  • 95
  • 151
9
votes
1 answer

Mapping generic spreaded argument types in TypeScript

I'm trying to write a generic method that takes any number of arguments that are keys to an object and use the values of their keys as arguments to a constructor. This is my original implementation: // Typescript 2.x export function…
Nathan Bierema
  • 1,813
  • 2
  • 14
  • 24
9
votes
6 answers

difference between IEnumerable.Reverse & List.Reverse

Why IEnumerable.Reverse() returns the reversed collection with the original collection and List reverses the original collection itself? This is somewhat confusing to me since List inherits from IEnumerable.
Prasanna
  • 187
  • 1
  • 10
9
votes
3 answers

Can't change struct's members value inside generic collections

Imagine this struct : struct Person { public string FirstName { get; set; } public string LastName { get; set; } } And following code : var list = new List(); list.Add(new…
Saber Amani
  • 6,409
  • 12
  • 53
  • 88
8
votes
4 answers

List interface: from Java to C#

I'm a Java programmer learning C# these days. Usually in Java when using lists, it should be preferrable programming against its interface in order to switch between implementations: List list = new ArrayList(); //or list = new…
Heisenbug
  • 38,762
  • 28
  • 132
  • 190
8
votes
2 answers

Java method that returns a function?

I'm using Guava collections' transform functions, and finding myself making a lot of anonymous functions like this pseudocode: Function TransformFunction = new Function() { public R apply(T obj) { // do what you…
ewall
  • 27,179
  • 15
  • 70
  • 84
8
votes
7 answers

How to remove from List efficiently (C#)?

If I understood correctly (and please correct me if i'm wrong), list is implemented by array in .NET, which means that every deletion of an item in the list will cause re-allocation of all the list (which in turn means O(n)). I'm developing a game,…
OopsUser
  • 4,642
  • 7
  • 46
  • 71
7
votes
6 answers

Type-safe generic containers with macros

I'm trying to make a type-safe generic linked list in C using macros. It should work similarly to how templates work in C++. For example, LIST(int) *list = LIST_CREATE(int); My first attempt was for #define LIST(TYPE) (the macro I used above) to…
Paul Manta
  • 30,618
  • 31
  • 128
  • 208
7
votes
2 answers

Anyone know of a good LinkedDictionary/Hashed LinkedList?

I am in need of a Generic collection that is somewhere in between a Dictionary and LinkedList. I want to be able to: Access elements by key Access previous and next elements I've taken a look at the provided Generic collections as well as the…
7
votes
4 answers

Java - Obtaining generic object as String Generic type throws exception

public class Box { private T element; public T getElement() { return element; } public void setElement(T element) { this.element = element; } } public class Test { public static void main(String[]…
Thiyagu
  • 17,362
  • 5
  • 42
  • 79
1
2
3
25 26