I am writing an application where memory, and to a lesser extent speed, are vital. I have found from profiling that I spend a great deal of time in Map and Set operations. While I look at ways to call these methods less, I am wondering whether anyone out there has written, or come across, implementations that significantly improve on acc...
Hi, I am using a StringDictionary to store key value pairs. I need to use the keys and values interchangeably i.e. I should be able to get the key from the value as in my case the values will be distinct.
Is there a direct way I could do it (without looping)? Or if there is any other collection I could use to achieve this?
Currently I...
I happen to use this kind of structure quite a lot:
Dictionary<string, List<string>> Foo = new Dictionary<string, List<string>>();
Which leads to this kind of code :
foreach (DataRow dr in ds.Tables[0].Rows)
{
List<string> bar;
if (!Foo.TryGetValue(dr["Key"].ToString(), out desks))
{
bar= new List<string>();
...
I have a winforms application that i added a DataGridView bound to a subsonic collection via a BindingSource to it.
The grid works fine for adding/editing (except for the display of the ComboBox column) but i can't get it to delete rows correctly from the database.
If i delete a row from the DataGridView, i can't problematically determ...
Is there a way to make the following implementation in a type safe manner?
public void myMethod( Map<String, ? extends List<String>> map )
{
map.put("foo", Collections.singletonList("bar");
}
The above implementation doesn't work. It requires a Map<String, ? super List<String>> to compile the method map.put() correctly. But myMetho...
I need to fill a tree-like UI control with some items (of course in parent-child1-child2-...childN relations) and before proceeding I want to ensure that the my collection that holds the content is ordered properly as follows:
Each object(in this case an instance of my Category class) from my collection (ObservableCollection that is not...
The java.util.Properties class is meant to represent a map where the keys and values are both Strings. This is because Properties objects are used to read .properties files, which are text files.
So, why in Java 5 did they retrofit this class to implement Map<Object,Object> and not Map<String,String>?
The javadoc states:
Because P...
Duplicate of: Why Dictionary is preferred over hashtable in C#?
What is the difference between Dictionary and Hashtable. How to decide which one to use?
...
Let's say I have a Farmer class, and a Farmer has a collection of Pigs.
If I use an ORM like Hibernate, I can cascade updates to a Farmer's Pig collection, such that I can do something like this from my controller:
Pig pig = new Pig("Charlie");
farmer.addPig(pig);
farmerService.save(farmer);
My farmer service doesn't know anything ab...
Using Linq on collections, what is the difference between the following lines of code?
if(!coll.Any(i => i.Value))
and
if(!coll.Exists(i => i.Value))
Update 1
When I disassemble .Exists it looks like there is no code.
Update 2
Anyone know why there is not code there for this one?
...
I've read Neal Gafter's blog on the subject and am still unclear on a number of points.
Why is it not possible to create a implementations of the collections api that preserve type information given the current state of Java, the JVM and existing collections API? Couldn't these be them replace the existing implementations in a future ve...
Does there exist a site which hosts collections of unit tests in various fields?
specifically, instead of digging and extracting the packages that seem close to your subject of coding, I'd like to use it like shared code, see how it was tested. (and then also know how it should work)
So is there one like that?
doesn't matter which progr...
Below is a question from Kathy & Bert Bates SCJP 5 preparation CD. I have posted this elsewhere too, but have not gotten a satisfactory explanation until now.... Please help me understand this:
public class BackLister {
//Insert code here
{
List<T> output=new LinkedList<T>();
for(T t:input)
output.add(0,t);
...
I'm new to Java and very confused.
I have a large dataset of length 4 int[] and I want to count the number of times
that each particular combination of 4 integers occurs. This is very similar to counting word frequencies in a document.
I want to create a Map<int[], double> that maps each int[] to a running count as the list is iterate...
Suppose I have an IEnumerable such as a List(TValue) and I want to keep track of whether this list is being accessed (to prevent issues with, say, adding to the list while it is being iterated over on a different thread); I can always write code such as the following:
Dim List1 As New List(Of Integer)
Dim IteratingList1 As Boolean = Fal...
Is there a good way to enumerate through only a subset of a Collection in C#? That is, I have a collection of a large number of objects (say, 1000), but I'd like to enumerate through only elements 250 - 340. Is there a good way to get an Enumerator for a subset of the collection, without using another Collection?
Edit: should have men...
I am wondering what is the best way to use properties when dealing with collections.
For example I have a class Foo and I want to have a list of that class stored. Which of the following should be used:
private List<Foo> myList;
private List<Foo> myOtherList = new List<Foo>();
now for the property:
public List<Foo> ListOfFoo
{
...
In ASP.NET 3.5, is it possible to iterate through all of the session objects (not the objects within the current session, but all sessions across all users) so that their collection contents can be manipulated (i.e. one collection item removed from all active sessions)?
And if so, does this work with ASP.NET State Service (accessing all...
i want to sort dictionary based upon value of each dictioanry item.but if i use sorted dictionary search time complexity will increase from constant to log2(n).so i want to directly assign reference of value list in dictionary to a list.then i can sort this list and get results.i dont want to iterate to each element of dictionary to add ...
Situation:
I have some persons with certain skills and they can/might belong to more than one area.
The skills are linked in a seperate table, so are the areas.
I get the people list from selecting all persons with a match on each skill and add them to a list where I can use Distinct() to make sure that they dont show up twice.
Result...