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

SortedBag for C#

I'm looking for a SortedBag implementation for C#, my use case is the following: I have a series of objects that are being estimated and sorted out using custom IComparer implementation, the problem is that totally different objects may yield to the…
Lu4
  • 14,873
  • 15
  • 79
  • 132
4
votes
2 answers

How to Sort a Map> by the Key with the most values (that are not numeric) assigned to it

I have been working with Maps at present and I am baffled by how I can get my program to work effectively. I can iterate over the map get the keys and values and sort them in alphabetical and reverse alphbetical order quite easily and have used…
BigRikk
  • 43
  • 1
  • 5
4
votes
1 answer

Implementing Custom Binary Search for TObjectList (Delphi XE)

I need to implement a binary search on TObjectList that uses a custom comparer, I believe using TCustomComparer. Goal: binary search returns instances in the list that conform to a particular property parameter. For example: TMyClass=class …
Vector
  • 10,879
  • 12
  • 61
  • 101
3
votes
3 answers

How do i add items to a generic collection?

Given: public static void DoStuff(ICollection source) { Customer c = new Customer(); .... source.Add(c); } except c is not of type . So how do i add an item to a generic collection? i tried having: public static void…
Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
3
votes
2 answers

C # equivalent of Java List

I have a basic structure of generic's classes public class Parent where T : Parent { Action Notify; } public class Child : Parent { } And I want to have a list so that Child objects can be put there List parents = new…
lancaster
  • 134
  • 9
3
votes
2 answers

Java Generic issue: cannot cast Map to M extends Map

While trying to write some Generic code I faced an issue. Of course, I found some workarounds, but still, why the code below is not working? private static > Supplier mapSupplier() { return HashMap::new; } This…
Seventh
  • 107
  • 5
3
votes
3 answers

Storing objects conforming to a protocol with generics in a typed array

I've got a protocol: protocol Adjustable: Equatable { associatedtype T var id: String { get set } var value: T { get set } init(id: String, value: T) } And a struct that conforms to it: struct Adjustment: Adjustable { static…
brandonscript
  • 68,675
  • 32
  • 163
  • 220
3
votes
1 answer

Why HashSet object deserialisation give uncheck warning in my code ? | Java | IntelliJ idea |

In my code, when I try to deserialize the HashSet object it gives me this warnings : Unchecked assignment:'java.util.HashSet' to'java.util.HashSet Inspection info: Signals places where an unchecked warning is issued by the…
H.Das
  • 225
  • 2
  • 9
3
votes
4 answers

c# Array or Collection

How would you approach this? I have a list of data that has two things that need to be stored price and item, is there anyway to store this in an array without knowing the total number of rows that I will have? Or should I use a collection can those…
atrljoe
  • 8,031
  • 11
  • 67
  • 110
3
votes
1 answer

How can I add child object to the parent generic type in c#

In java I can do it with extends keyword in Generic Type but in C# I cannot figure out. I have a 3 classes, one of them is the base class. public class BaseEntity { public string Id {get;set;} } public class EntityA : BaseEntity {} public…
Dabagab
  • 2,497
  • 4
  • 26
  • 31
3
votes
3 answers

What signature should a generic method in Java have so that It can accept any > and...?

I want to create a method that traverses through any collection that stores ArrayList - let's call that collection T; for example, it can be LinkedList, ArrayList or any other Collection; U - is another type which is needed to be memorized; and…
3
votes
3 answers

Group By Raw Data from DB

This is my raw data coming from DB: PrimaryColumn StudentId StudentName CourseName CourseId CourseDuration 1 1 X Cse1 C1 2 2 1 X Cse2 C2 1…
3
votes
1 answer

How to make red-black tree generic in java

I am working on red-black tree and wrote its full working code which I have shown below. I went through Generics tutorial and understood that with single class declaration, it is possible to specify a set of related method. How can I apply it to my…
John Doe
  • 77
  • 1
  • 9
3
votes
4 answers

Sum values of a Dictionary for specific keys C#

I have a dictionary with two similar keys, one is misspelled so it created another key, that I would like to sum the values of, and delete the key/value pair that is misspelled. If I have a dictionary of departments, with the department name as the…
miken
  • 387
  • 1
  • 4
  • 15
3
votes
1 answer

Is it possible to write a generic JSON Schema?

Inside my root JSON object I have many JSON objects of two different types. I'm wondering if there is a way to write a JSON schema to validate these objects without getting specific, i.e. generic schema. For example, imagine I have the following…
visc
  • 4,794
  • 6
  • 32
  • 58