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
4
votes
3 answers

Accesing a method in the last object in a LinkedHashMap

I've got a LinkedHashMap that contains an object at key and one at value. I've used the code yourShots.keySet().toArray()[yourShots.size()-1] to return the last object of the keys. However, I am unable to access a method that the object has. I've…
Brian
  • 119
  • 6
4
votes
1 answer

Why do we need hashcode and bucket in LinkedHashMap

Lately,I've been going through implementations of Map interface in java. I understood HashMap and everything made sense. But when it comes to LinkedHashMap, as per my knowledge so far, the Entry has key, value, before and after. where before and…
Arun Gowda
  • 2,721
  • 5
  • 29
  • 50
4
votes
2 answers

Multi-dimensional byte arrays with LinkedHashMap... Is there a better way?

I'm VERY new to Java Programming, so please forgive my newbish questions :). I am using a LinkedHashMap as a file cache for an application I am modifying for the sake of assisting development. I am doing this to reduce I/O overhead, and hence…
Mike Lehe
  • 41
  • 2
4
votes
1 answer

LRU cache on top of shared preferences

I would like to create an LRU cache that is backed by the shared preferences. Basically I would like to store a specific number of strings (around 20) and have an LRU behavior. I know that LinkedHashMap is an LRU in java but is there a way to…
Jim
  • 18,826
  • 34
  • 135
  • 254
4
votes
2 answers

Javaslang / Vavr LinkedHashMap from List

Is there a concise, idiomatic way to create an order-preserving map from a Javaslang / Vavr List? List.toMap() returns a plain HashMap, so that doesn't do it. What I have right now is something like this -- listOfKeys.foldLeft( …
David Moles
  • 48,006
  • 27
  • 136
  • 235
4
votes
1 answer

How to preserve LinkedHashMap ordering in JSONObject?

I have a LinkedHashMap with states. Map stateMap = new LinkedHashMap(); // ... I'm creating a JSONObject based on it. JSONObject json = new JSONObject(); json.putAll(stateMap); However, the entries appear unordered.…
4
votes
1 answer

Word cooccurence in sentences

I have a large set of sentences (10,000) in a file. The file contains one sentence per file. In the entire set, I want to find out which words occur together in a sentence and their frequency. Sample sentences: "Proposal 201 has been accepted by…
4
votes
1 answer

Use of doubly Linked List in LinkedHashMap over Single LinkedList

I know my question is very much similar to one which are posted previously.I have gone through multiple post for this but still not very much clear with the answer.That's why i am posting it again. Why Linked HashMap uses doubly LinkedList over…
Manish
  • 1,274
  • 3
  • 22
  • 59
4
votes
5 answers

Reflection - Getting different results from HashMap - LinkedHashMap

I'll keep it brief, I have a Dog class like the following: public class Dog { public void Foo() { System.out.println("Right Call"); } public void Boo() { System.out.println("Wrong Call"); } } and a main method like…
Burak.
  • 598
  • 7
  • 19
4
votes
3 answers

Move Item in LinkedHashMap

Is there a way to move an item within a LinkedHashMap? Specifically, I'd like to move an item to the first position. I know that if I wanted to add an item to the end, I could just do: LinkedHashMap items = new…
Adam_G
  • 7,337
  • 20
  • 86
  • 148
4
votes
1 answer

Does a collection which is retrieved from map.values() method preserve insertion order?

I have an instance of LinkedHashMap. LinkedHashMap preserves the insertion order. I need to get the values of this map and I need them to be in the same order. So if I call values() method on this LinkedHashMap, the Collection that I retrieve from…
4
votes
4 answers

What is LinkedHashMap and what is it used for?

When I was going through a example code which has ListViews I came up with LinkedHashMap. What is a LinkedHashMap and where can we use it and how? I went through several articles but did not understand fully. Is it necessary when creating ListView.…
CraZyDroiD
  • 6,622
  • 30
  • 95
  • 182
4
votes
3 answers

LinkedHashMap vs HashMap, LinkedHashSet vs HashSet

I know the difference between all of them and I understand that LinkedHashMap and LinkedHashSet provide an insertion-ordering. I understand that LinkedHashMap extends HashMap and LinkedHashSet extends HashSet. Why don't we always use LinkedHashMap…
O Connor
  • 4,236
  • 15
  • 50
  • 91
4
votes
5 answers

Java LinkedHashMap: what's the difference in these two?

EDIT: The entire code and database creation script can be found from http://gitorious.org/scheator . The database script is in Schema/. I have the following Java code: A LinkedHashMap defined in an abstract class as LinkedHashMap
Makis
  • 12,468
  • 10
  • 62
  • 71
4
votes
2 answers

Android LinkedHashMap.eldest() method is NOT available

I see the LinkedHashMap.eldest() method when attaching the source but cannot use it. Any idea why it isn't available?
AlikElzin-kilaka
  • 34,335
  • 35
  • 194
  • 277