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

how to make Scala canBuildFrom to build collection type from Seq to Set

I did experiment on CanBuildFrom trait on Scala, it looks fine when I try to convert Array type to Seq type automatically, I think the reason is that we have CanBuildFrom[Array, T, Seq[T]] in the scope. However, if I try to convert Array to Set, it…
3
votes
3 answers

Java ArrayList indexOf generic type

ArrayList described as public class ArrayList extends AbstractList implements List, RandomAccess, Cloneable, java.io.Serializable And most of main methods work with E generic type (get, set, add, addAll etc). But methods contains,…
Vladimir Kishlaly
  • 1,872
  • 1
  • 16
  • 26
3
votes
2 answers

Generic foreach loop for different property

I am trying to use a generic method for foreach loop which would pass different parameter as the argument. In this example below I would like to pass different parameters(EmployeeDisplayOrder or EmployeeEnrollOrder) public void…
Ell
  • 83
  • 1
  • 1
  • 7
3
votes
1 answer

Boxing and Unboxing with Generic Collections

In interview i had been asked for Boxing and Unboxing and i explained it. After that i asked for Generic Collections. I explained the below code and from here they asked how boxing operation applied here in the below code. I am not sure about this…
user1618825
3
votes
3 answers

VB.NET: Get dynamically value of constants

If have got the following definitions of constants: Protected Const Xsl As String = "Configuration.Xsl" Protected Const Form As String = "Settings.Form" Protected Const Ascx As String = "Implementation.Ascx" ... To fill a dictionary I use this…
mburm
  • 1,417
  • 2
  • 17
  • 37
3
votes
2 answers

Is there any performance difference between compare method and compare class?

Are there any difference in performance between List.Sort Method (Comparison) and List.Sort Method (IComparer)? Does exists any structural (software architectural) benefits? When do you use the compare method instead of compare class…
Forro Istvan
  • 307
  • 2
  • 6
  • 11
3
votes
2 answers

Generic types : wildcards vs variables of raw types

Consider following methods: public static void listAll(LinkedList list) { for(Object obj : list) System.out.println(obj); } and public static void listAll(LinkedList list) { for(Object obj : list) …
Sina Barghidarian
  • 450
  • 1
  • 4
  • 18
3
votes
1 answer

Generic collections in vba?

Does VBA have Generic collections? I am relatively new to VBA. I see it has dictionary data structure. What are the other collections or data structures that vba have?
sid
  • 31
  • 2
3
votes
1 answer

How to implement a custom typesafe collection using generic collections?

I used a strongly typed collection that derived from the CollectionBase class and now I'd like to change it to inherit from a typesafe generic collection. Some advise to inherit from List, some do advise to use Collection. What I'd like to do…
3
votes
3 answers

implementing compareTo() with generics and collection

i m working with collections and i cant figure this out... I want to override compareTO() method based on the "data" variable in the Node class.. so that i can invoke collection.sort() to sort the arraylist.. public class Node implements…
madhur
  • 357
  • 2
  • 6
  • 17
2
votes
1 answer

One object pool to contain different derived classes

Short version: How would i go about creating an object pool that can store classes of different types all derived from the same base class? See below for an example of expected usage. Long version: I have a class BaseComponent, with many derived…
George Duckett
  • 31,770
  • 9
  • 95
  • 162
2
votes
4 answers

Simple generic collection to add elements

What collection should I use from C# that suports generic only for adding elements ? I tried using ArrayList, but I see that it's a non-generic type. Sorry if this is a duplicate. Thanks.
Adrian
  • 19,440
  • 34
  • 112
  • 219
2
votes
1 answer

Unmarshalling a TreeSet in JAXB

I have a class that I wish to populate with content from an XML file using JAXB. My XML file looks similar to this: First Item Second Item My JAXB annotated…
seanhodges
  • 17,426
  • 15
  • 71
  • 93
2
votes
1 answer

Incomplete System.Collections.Generic in Visual C# 2010 Express

I'm trying to access System.Collections.Generic.Stack<> in Visual C# 2010 Express, but the IDE (and compiler) claim that it's not present. Several other classes are also missing, including LinkedList<>, SortedList<> and Queue<>. I've checked the…
Catalept
  • 23
  • 4
2
votes
1 answer

Java generics assignability

I am struggling a bit on assign-ability of generic type parameters. Here are how my type definitions look: public static interface CellValue { T getValue(); Class getType(); } public static class DoubleCell implements…
DebD
  • 373
  • 3
  • 20