collections

Removing alternate elements in a List<T>

What is the most efficient way to remove alternate (odd indexed or even indexed) elements in an List<T> without using a place holder list variable? Also it would be appreciated if you could mention the cost with each of your answer. I'm looking for an efficient way to do this Thanks in advance ...

Using a dictionary when the Key and the Value are the same?

I want to hold about 30 strings in a static "collection". I then need to check the path of an incoming web request against this list. I was thinking of using a StringDictionary with the Key and the Value having the the same values. However it just seems odd when all I really want is a key look up, so I can check for existence rather tha...

Java: How to remove elements from a list while iterating over/adding to it

Hi! This question is a more special case of the problem described (and solved) in this question. I have two methods, stopAndRemove(ServerObject server) and a close() method. The later should close all servers and remove them from the server list. The list is defined as List<ServerObject> server. I do not want to have almost the same...

large object cache

I have a .NET2.0 C# web-app. It has a variable number of large, init-expensive objects which are shared across multiple requests but not sessioned to any given user. I therefore need to persist them in a lookup structure. These objects need to be created as required and are not required for the lifespan of the app, merely the lifespan of...

Can you have more than 2 items in a Dictionary collection or another type of collection?

I doubt this is possible, but I was curious if you could have more than 2 items (key,value) in a dictionary. Maybe a key and 2 values. Is there a collection object that does allow this? What I am actually trying to do is to store a key and a value for the key and another value to hold the count of how many times the key has been found....

StringDictionary vs Dictionary<string, string>

Does anyone have any idea what the practical differences are between the System.Collections.Specialized.StringDictionary object and System.Collections.Generic.Dictionary? I've used them both in the past without much thought as to which would perform better, work better with Linq, or provide any other benefits. Any thoughts or suggestio...

What is the most efficient Java Collections library?

What is the most efficient Java Collections library? A few years ago, I did a lot of Java and had the impression back then that trove is the best (most efficient) Java Collections implementation. But when I read the answers to the question "Most useful free Java libraries?" I noticed that trove is hardly mentioned. So which Java Collect...

Should collections also be responsible for creating objects? (Single Responsibility Pattern)

Should a collection of objects also be responsible for creating new objects? Let me explain. I have two classes, PhoneCall and PhoneCallList. PhoneCallList is a collection of PhoneCall objects. Our architect and I are at odds on how to go about creating new PhoneCall objects. Currently the PhoneCall object has a method called Crea...

Anyone know of a java.util.Map implementation optimized for low memory use?

I've looked in the usual places (apache commons, google) and not been able to find one ... It should be opensource. Pretty much looking for one based on a linked list. The use case is 10'000's of maps, with not necessarily many values in. It does not need to scale up, as i can convert it when it gets too big. Some numbers, sizes usin...

C# Cannot convert from IEnumerable<Base> to IEnumerable<Derived>

I recently run into trouble when trying to AddRange(IEnumerable) to a List. Probably a classic issue, but I do not really get it yet. I understand that methods expecting a List parameter are not satisfied with a List, because they might try to add a Base to the List, which is obviously impossible. But if i get this correctly, since IEn...

Any disadvantage to using arbitrary objects as Map keys in Java?

I have two kinds of objects in my application where every object of one kind has exactly one corresponding object of the other kind. The obvious choice to keep track of this relationship is a Map<type1, type2>, like a HashMap. But somehow, I'm suspicious. Can I use an object as a key in the Map, pass it around, have it sitting in anothe...

Oracle sql types over dblink

I have two schemas: A and B (Oracle 9). At the A there is a dblink to B. At the B there is a package, that i calls from A. Procedures in B package can returns varying count results and i think that returning a collection is a better way for this reason. create type B.tr_rad as object ( name varchar2(64) ,code number ,vendor ...

What is a practical, real world example of the Linked List?

I understand the definition of a Linked List, but how can it be represented and related to a common concept or item? For example, inheritance in OOP can be related to automobiles. All (most) automobiles in real life are the essentially same thing; an automobile has an Engine, you can start() it, you can make the car go(), stop() and ...

Common problem for me in C#, is my solution good, stupid, reasonable? (Advanced Beginner)

Ok, understand that I come from Cold Fusion so I tend to think of things in a CF sort of way, and C# and CF are as different as can be in general approach. So the problem is: I want to pull a "table" (thats how I think of it) of data from a SQL database via LINQ and then I want to do some computations on it in memory. This "table" conta...

Is there any way to enforce typing on NSArray, NSMutableArray, etc.?

Can I make an NSMutableArray where all the elements are of type SomeClass? ...

The best way to iterate SortedSet / SortedMap in Java backwards

I need to iterate through SortedMap's entry set (which is a SortedSet) backwards. The code I'm writing is extremely performance-sensitive, as it's going to be called from many places thousands times per second, maybe more. Any advice on doing it the fastest way? ...

How to conditionally remove items from a .NET collection

Hi all, I'm trying to write an extension method in .NET that will operate on a generic collection, and remove all items from the collection that match a given criteria. This was my first attempt: public static void RemoveWhere<T>(this ICollection<T> Coll, Func<T, bool> Criteria){ foreach (T obj in Coll.Where(Criteria)) Col...

What is the best way to determine the initial capacity for collection objects?

When using objects that have a capacity, what are some guidelines that you can use to ensure the best effeciency when using to collections? It also seems like .NET framework has set some of these capacities low. For example, I think StringBuilder has an intial capacity of 16. Does this mean that after 16 strings are inserted into the ...

Is there a Java Collection (or similar) that behaves like an auto-id SQL table?

Note that I'm not actually doing anything with a database here, so ORM tools are probably not what I'm looking for. I want to have some containers that each hold a number of objects, with all objects in one container being of the same class. The container should show some of the behaviour of a database table, namely: allow one of the ...

Creating Type Safe Collections in Flex

I'm trying to create a collection class in Flex that is limited to housing a specific type of data that i am using (an interface). I have chosen not to extend the ArrayCollection class as it's too generic and doesn't really give me the compile time safety that i'm after. In it's simplistic form my collection contains an array and i man...