Questions tagged [linkedhashmap]

LinkedHashMap is a Hash table and linked list implementation of the Map interface in the Java Standard library. This implementation provides a predictable iteration order, in contrast with the unspecified ordering provided by HashMap, which is normally the order in which keys were inserted into the map.

703 questions
5
votes
0 answers

Linked Map in Java, being unequal if order of keys is different

Is there a Map in Java or 3rd-party libraries preserving insertion order (similar to LinkedHashMap) which would also check order of keys during comparison (equals() and hashCode() methods) ? So that Map(a => 1, b => 2) would be different from Map(b…
Zbynek Vyskovsky - kvr000
  • 18,186
  • 3
  • 35
  • 43
5
votes
3 answers

Collection.unmodifiableMap iteration order

Does Colelction.unmodifiableMap safeguard the iteration order? I was trying newMap.put(key,Collections.ModifiableMap(oldMap)) Then when I do newMap.get(key) and iterate, iterate order seems to change. How can we protect the iterate order?
Chandra
  • 777
  • 3
  • 12
  • 18
5
votes
6 answers

Does an ArrayList created from the keySet() of LinkedHashMap preserves the order of insertion?

I get data something like {"Employee 1 of ABC", "ABCX"}, {"Employee 2 of ABC", "ABCY"}, {"Employee 3 of ABC", "ABCZ"} from database through a RefCursor. I have a case where I need to preserve the order in which data is read from the…
spiderman
  • 10,892
  • 12
  • 50
  • 84
5
votes
1 answer

Efficient alternative to Map in Java, with regards to autoboxing?

I'm using a LinkedHashMap to store values of layers on a tile in a 2D game. Higher numbers are drawn over the lower numbers. In my draw function, I iterate through the value set and draw each one. This means I'm unboxing values…
Audiocrow
  • 65
  • 5
5
votes
2 answers

serialize/deserialize a LinkedHashMap (android) java

So i want to pass a LinkedHashMap to an intent. //SEND THE MAP Intent singlechannel = new Intent(getBaseContext(),singlechannel.class); singlechannel.putExtra("db",shows1);//perase to startActivity(singlechannel); //GET THE…
weakwire
  • 9,284
  • 8
  • 53
  • 78
5
votes
1 answer

LinkedHashMap$Entry cannot be cast to java.util.LinkedHashMap

I'm wrapped LinkedHashMap> into a List with; List>> list = new ArrayList(mainCodesMap.entrySet()); which mainCodeMap is type of Map> the…
quartaela
  • 2,579
  • 16
  • 63
  • 99
5
votes
2 answers

what happens if we 'put' and new value to an already existing key in the Linkedhashmap

I have a fixed set of key value pairs with which I am initializing the LinkedHashMap. Does the insertion order remain the same when I do a LinkedHashMap.put(existingKey, newValue); To be precise my question is, when we update a…
codeMan
  • 5,730
  • 3
  • 27
  • 51
5
votes
3 answers

ConcurrentModificationException even with using Collections.sychronizedMap on a LinkedHashMap

I'm using a Map object in my class that I've synchronized with Collections.synchronizedMap() for a LinkedHashMap like so: private GameObjectManager(){ gameObjects = Collections.synchronizedMap(new LinkedHashMap()); } I'm…
5
votes
1 answer

LinkedHashMap's impl - Uses Double Linked List, not a Single Linked List; Why

As I referred to the documentation of LinkedHashMap, It says, a double linked list(DLL) is maintained internally I was trying to understand why a DLL was chosen over S(ingle)LL The biggest advantage I get with a DLL would be traversing backwards,…
smc
  • 710
  • 1
  • 9
  • 26
5
votes
2 answers

How to sort a LinkedHashMap by its value class's field?

I use the following lines to sort a LinkedHashMap, but not all items are sorted, anything wrong ? LinkedHashMap statisticsMap; // fill in the map ... LinkedHashMap sortedStatisticsMap=new…
Frank
  • 30,590
  • 58
  • 161
  • 244
5
votes
1 answer

Groovy/Grails LinkedHashMap behaving weirdly

I'm running into some confusing behaviour from LinkedHashMap in grails 2.0.3. Running the following script in grails console: def m = ["smart-1":[stuff:'asdf']] println m.getClass() def p = [id:1] println m."smart-$p.id" println…
Alex
  • 95
  • 1
  • 5
4
votes
3 answers

Soft reference LinkedHashMap in Java?

Is there softreference-based LinkedHashMap in Java? If no, has anyone got a snippet of code that I can probably reuse? I promise to reference it correctly. Thanks.
His
  • 5,891
  • 15
  • 61
  • 82
4
votes
3 answers

Java: Flat List> to Hierarchical List>

This issue seems to be pretty complex so here I'm posting this issue for any possible way to solve this. I have list of Maps. I want again a list of map, but making sure the map is converted into some sort of hierarchy. Original data:…
Jake
  • 391
  • 1
  • 4
  • 22
4
votes
3 answers

How to convert LinkedHasMap Values into ArrayList/Array in right order?

I'm getting LinkedHashMap grades = courses.get(choise).getGrades(); I need to save the grades values in an array/arraylist. I'm able to get values and keys in loop String key = ""; String value = ""; for (Object o : grades.keySet()){ key =…
G. Dawid
  • 162
  • 1
  • 11
4
votes
3 answers

Getting 'Type mismatch: cannot convert from ArrayList> to List>' while instantiating a list of maps

List> recordMapList = new ArrayList>(); The above line gives the error: Type mismatch: cannot convert from ArrayList> to List> But the issue goes away if use HashMap instead of Map in the left hand…
DockYard
  • 989
  • 2
  • 12
  • 29