collections

Create all word variations of 2 character arrays

I have 2 collections of caracter string ex: List<string> one = new List<string>; one.Add("a"); one.Add("b"); one.Add("c"); List<string> two = new List<string>; two.Add("x"); two.Add("y"); two.Add("z"); What i would like to do is create a list of all the variations of words that can be created from this. But i only want to create 4 c...

What is the big deal with IQueryable?

I've seen a lot of people talking about IQueryable and I haven't quite picked up on what all the buzz is about. I always work with generic List's and find they are very rich in the way you can "query" them and work with them, even run LINQ queries against them. So I'm wondering if there is a good reason to start considering a differen...

Null-free "maps": Is a callback solution slower than tryGet()?

In comments to "How to implement List, Set, and Map in null free design?", Steven Sudit and I got into a discussion about using a callback, with handlers for "found" and "not found" situations, vs. a tryGet() method, taking an out parameter and returning a boolean indicating whether the out parameter had been populated. Steven maintained...

[C#] How to create a constructor of a class that return a collection of instances of that class?

My program has the following class definition: public sealed class Subscriber { private subscription; public Subscriber(int id) { using (DataContext dc = new DataContext()) { this.subscription = dc._GetSubscription(id).SingleOrDefault(); } } } ,where _GetS...

Java - Thread safety of ArrayList constructors

I am looking at this piece of code. This constructor delegates to the native method "System.arraycopy" Is it Thread safe? And by that I mean can it ever throw a ConcurrentModificationException? public Collection<Object> getConnections(Collection<Object> someCollection) { return new ArrayList<Object>(someCollection); } Does it mak...

Lazy non-modifiable list in Google Collections

I was looking for a decent implementation of a generic lazy non-modifiable list implementation to wrap my search result entries. The unmodifiable part of the task is easy as it can be achieved by Collections.unmodifiableList() so I only need to sort out the the lazy part. Surprisingly, google-collections doesn't have anything to offer; ...

Python, concise way to test membership in collection using partial match

hello. What is the pythonic way to test if there is a tuple starting with another tuple in collection? actually, I am really after the index of match, but I can probably figure out from test example for example: c = ((0,1),(2,3)) # (0,) should match first element, (3,)should match no element I should add my python is 2.4 and/or 2.5...

Concurrent Linked HashMap java

Please help me use/create Concurrent LinkedHashMap in multithreaded architecture. As per my belief, if I use Collections.synchronizedMap(), I would have to use synchronized blocks for iterator. Would this implementation lead to sequential addition of elements If I use ConcurrentSkipListMap<String,String> is there any way to implement a...

How to implement a collection (list, map?) of complicated strings in Java?

Hi all. I'm new here. Problem -- I have something like the following entries, 1000 of them: args1=msg args2=flow args3=content args4=depth args6=within ==> args5=content args1=msg args2=flow args3=content args4=depth args6=within args7=distance ==> args5=content args1=msg args2=flow args3=content args6=within ==> args5=content args1=ms...

Populating and Using Dynamic Classes in C#/.NET 4.0

In our application we're considering using dynamically generated classes to hold a lot of our data. The reason for doing this is that we have customers with tables that have different structures. So you could have a customer table called "DOG" (just making this up) that contains the columns "DOGID", "DOGNAME", "DOGTYPE", etc. Customer...

C#: How to remove items from the collection of a IDictionary<E, ICollection<T>> with LINQ?

Here is what I am trying to do: private readonly IDictionary<float, ICollection<IGameObjectController>> layers; foreach (ICollection<IGameObjectController> layerSet in layers.Values) { foreach (IGameObjectController controller in layerSet) { if (controller.Model.DefinedInV...

Why collection literals ?

Hi fellow Java programmers. From the various online articles on Java 7 I have come to know that Java 7 will be having collection literals like the following: List<String> fruits = [ "Apple", "Mango", "Guava" ]; Set<String> flowers = { "Rose", "Daisy", "Chrysanthemum" }; Map<Integer, String> hindiNums = { 1 : "Ek", 2 : "Do", 3 : "Teen" ...

java generics and the addAll method

What is the correct type of argument to the addAll(..) method in Java collections? If I do something like this: List<? extends Map<String, Object[]>> currentList = new ArrayList<Map<String, Object[]>>(); Collection<HashMap<String, Object[]>> addAll = new ArrayList<HashMap<String, Object[]>>(); // add some hashmaps to the list.. currentL...

Most Efficient to pass a collection of Char to method for population

Is this the best way to get a collection of chars? Wondering is it overkill to use List for primitives such as char? private void GetChars(ref List<char> charsToPopulate) { foreach(Thing t in Things) { charsToPopulate.Add(t.CharSymbol); } } ...

Iteration order of HashSet

If every object added to a java.util.HashSet implements Object.equals() and Object.hashCode() in a deterministic fashion, is the iteration order over the HashSet guaranteed to be identical for every identical set of elements added, irrespective of the order in which they were added? Bonus question: what if the insertion order is identic...

WPF: change DataTemples according to Value

I have a class called Cell with two properties. One is called Value of type int? And the other is called Candidates of type ObservableCollection<ObservableCollection<Candidate>> during the initialization I am utilizing a DataTemplateSelector to choose between two datatemplates for two different scenarios. If the Value property has a va...

Java ArrayList Middle

How to find the middle of an ArrayList ? ...

Using Custom Generic Collection faster with objects than List

I'm iterating through a List<> to find a matching element. The problem is that object has only 2 significant values, Name and Link (both strings), but has some other values which I don't want to compare. I'm thinking about using something like HashSet (which is exactly what I'm searching for -- fast) from .NET 3.5 but target framework ...

Difference between Array and List in scala

In what cases I should use Array(Buffer) and List(Buffer). Only one difference that I know is that arrays are nonvariant and lists are covariant. But what about performance and some other characteristics? ...

How to know if an enumerator has reached the end of the collection in C#?

Hello, I am porting a library from C++ to C#. The old library uses vectors from C++ and in the C# I am using generic Dictionaries because they're actually a good data structure for what I'm doing (each element has an ID, then I just use using TypeDictionary = Dictionary<String, Type>;). Now, in the C# code I use a loop like this one Typ...