collections

Java - Distinct List of Objects

I have a list/collection of objects that may or may not have the same property values. What's the easiest way to get a distinct list of the objects with equal properties? Is one collection type best suited for this purpose? For example, in C# I could do something like the following with LINQ. var recipients = (from recipient in recipien...

Aggregate list values in Scala

I am learning Scala and exploring some of the functional aspects of the language. Starting with a list of objects containing two parameters notional and currency, how can I aggregate the total notional per currency? //sample data val t1 = new Trade("T150310", 10000000, "GBP"); val t2 = new Trade("T150311", 10000000, "JPY"); val t3 = ne...

how to manipulate list in java

Edit: My list is sorted as it is coming from a DB I have an ArrayList that has objects of class People. People has two properties: ssn and terminationReason. So my list looks like this ArrayList: ssn TerminatinoReason 123456789 Reason1 123456789 Reason2 123456789 Reason3 568956899 Reason2 000000001 R...

finding weak reference objects in collections in java

A couple of questions regarding Java's WeakReference and Collections: Is there a library out there that implements Java's various data-set interfaces (eg Collection, List, Set, Queue etc) with WeakReference transparently? Like WeakHashMap is for the HashMap interface? Or is the common solution to simply create normal Collections and th...

How to convert from from java.util.Map to a Scala Map

A Java API returns a java.util.Map<java.lang.String,java.lang.Boolean>;. I would like to put that into a Map[String,Boolean] So imagine we have: var scalaMap : Map[String,Boolean] = Map.empty val javaMap = new JavaClass().map() // Returns java.util.Map<java.lang.String,java.lang.Boolean> You can't do Map.empty ++ javaMap, because t...

C# refugee seeks a bit of Java collections help

I need to store key/value info in some type of collection. In C#, I'd define a dictionary like this: var entries = new Dictionary<string, int>(); entries.Add("Stop me", 11); entries.Add("Feed me", 12); entries.Add("Walk me", 13); Then I would access the values so: int value = entries["Stop me"]; How do I do this in Java? I've see...

Java Collections Implimentations (e.g. HashMaps vs HashSet vs HashTable ...), what is the cost of choosing the wrong one?

In my code I default to using ArrayList for all Lists, HashMap for all maps, HashSet for all sets. From a practical standpoint how much am I losing in flexibility, scalability, readability and performance by choosing the wrong implementation? When does it make sense to spend time to decide to use one rather than another? I certainly se...

Is there type or interface that implements of collection and selected value??

I need a type that keeps track of a collection and the selected value in a collection, similar to what a list box would do. Is there an existing (non-gui control) collection for this? I know it's fairly simple but I would rather use Microsoft's provided type if there is one. Basically, this is what I want: interface ISelectionList<T>...

Does List<T> guarantee insertion order?

Say I have 3 strings in a List (e.g. "1","2","3"). Then i want to reorder them to place "2" in position 1 (e.g. "2","1","3"). I am using this code (setting indexToMoveTo to 1): listInstance.Remove(itemToMove); listInstance.Insert(indexToMoveTo, itemToMove); This seems to work BUT I am occasionally getting strange results; sometimes ...

Java - Collection base

What is the equivalent of C# CollectionBase in Java? ...

best way to get value from Collection by index

What is the best way to get value from java.util.Collection by index? Thanks. ...

Why does the Java List interface not support getLast()?

I'm trying to understand the API inconsistency in the Java standard collections library. There is no method in List or in AbstractList to get the last item, although one can simulate that with size and getIndex(). However, LinkedList supports that function. Any idea why it was decided not to support this method in the interface? ...

Multi-valued hashtable in Java

Is it possible to have multiple values for the same key in a hash table? If not, can you suggest any such class or interface which could be used? ...

Basic Sorting Question - C# - (Java Programmer Learning C#)

I'm working on sorting a list of objects, and unfortunately, I'm not quite getting the information from the debugging to see where I'm going wrong. I have a custom class that I implemented a CompareTo method in, and I call .Sort() on a List of items of that class. Unfortunately, my program never actually gets to the compareTo() method.....

How to implement event

class Foo(){ public List<string> SomeCollection; } I need to implement an event which can fires when something added or removed from the Collection. How to do this? ...

How does IEnumerable<T>.Reverse work?

I am checking out the code in the reflector, but I haven't yet found out how it can enumerate through a collection backwards? Since there is no count information, and enumeration always starts from the "start" of the collection, right? Is it a drawback in the .NET framework? Is the cost higher than regular enumeration? ...

Dictionary class

is it possible to have multiple values for a single key in the java dictionary class?? ...

How to retrieve current object from collections using DataBinder.Eval?

I am retrieving Objects from a collection and assigned objects and objects within objects to web user control from hosting web page. <uc1:bookmarksList runat ="server" Link =<%#DataBinder.Eval(Container.DataItem, "OLinks")%> where Olinks is the objects within current objects list in collections(e.g User is current object in collec...

Collection lookups; alternative to Dictionary

Hello: A TimeSheetActivity class has a collection of Allocations. An Allocation is a value object that is used by other objects in the domain as well, looking something like this: public class Allocation : ValueObject { public virtual StaffMember StaffMember { get; private set; } public virtual TimeSheetActivity Activity { get;...

What does <E> mean in Collection<E>?

What meaning has <E> on the code Collection<E>? ...