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
38
votes
5 answers

java collections - keyset() vs entrySet() in map

I put a string array elements is a map where elements of string array is key and frequency of word is value, e.g.: String[] args = {"if","it","is","to","be","it","is","up","me","to","delegate"}; then the map will have entries like [ if:1, it:2…
AllTooSir
  • 48,828
  • 16
  • 130
  • 164
36
votes
7 answers

HashMap vs LinkedHashMap performance in iteration over values()

Is there any performance difference between HashMap and LinkedHashMap for traversal through values() function?
MBZ
  • 26,084
  • 47
  • 114
  • 191
35
votes
6 answers

Use LinkedHashMap to implement LRU cache

I was trying to implement a LRU cache using LinkedHashMap. In the documentation of LinkedHashMap (http://docs.oracle.com/javase/7/docs/api/java/util/LinkedHashMap.html), it says: Note that insertion order is not affected if a key is re-inserted…
Lei Chen
  • 699
  • 1
  • 5
  • 13
34
votes
4 answers

Collect stream of EntrySet to LinkedHashMap

I want to collect the stream to a LinkedHashMap. I have a JSON resource that is stored in LinkedHashMap resources. Then I filter out JSON elements by streaming the EntrySet of this map. Currently I am collecting the…
xtra
  • 1,957
  • 4
  • 22
  • 40
33
votes
1 answer

Jackson JSON + Java Generics get LinkedHashMap

I have a question which is similar to some questions at stackoverflow but none really answer my problem. I use the ObjectMapper of Jackson and want to parse this JSON string into an List of User objects: [{ "user" : "Tom", "role" : "READER" }, {…
Markus Weigelt
  • 352
  • 1
  • 3
  • 6
26
votes
8 answers

LinkedHashMap in .NET

I wonder if there is a counterpart to java.util.LinkedHashMap in .NET? (ie. the elements are (re)ordered automatically if I access an element. (boolean accessOrder) ).
Schildmeijer
  • 20,702
  • 12
  • 62
  • 79
26
votes
5 answers

How to keep the order of elements in hashtable

I have a hashtable . values() method returns values in some order different from the order in which i am inserted.How can i get the values in the same order as i inserted?Using LinkedHashmap is an alternative but it is not synchronized.
Thomas Manalil
  • 1,657
  • 4
  • 16
  • 23
25
votes
12 answers

Cartesian Product of a List of Lists

I have a problem that is really kind of a general programming question, but my implementation is in Java, so I will provide my examples that way I have a class like this: public class Foo { LinkedHashMap> dataStructure; …
Chris Drappier
  • 5,280
  • 10
  • 40
  • 64
24
votes
2 answers

I need an immutable key-value structure that retains insertion order

I want to find something like ImmutableLinkedHashMap<> in Guava library. I need to use an immutable key-value data structure with an insertion order. So, what should I use?
Oleksandr Karaberov
  • 12,573
  • 10
  • 43
  • 70
22
votes
1 answer

How to get ordered type of Map from method Collectors.groupingBy

I need to separate list of data into different lists by type, for this purpose I use construction Map> dishMap = menu.stream() .collect(Collectors.groupingBy(Dish::getType)); but How can I get LinkedHashMap instead…
21
votes
5 answers

Convert from LinkedHashMap to Json String

I'm Workin with Mongo using Jongo, when I do a query I receive a LinkedHashMap as result. Iterator one = (Iterator) friends.find(query).projection("{_id:0}").as(Object.class); while (one.hasNext()) { LinkedHashMap data = new LinkedHashMap(); …
user1655510
  • 247
  • 1
  • 3
  • 10
21
votes
6 answers

ConcurrentModificationException with LinkedHashMap

Not sure what is triggering a java.util.ConcurrentModificationException when I iterate over the LinkedHashMap structure in the code below. Using the Map.Entry approach works fine. Did not get a good explanation on what is triggering this from the…
Aditya Sakhuja
  • 333
  • 1
  • 2
  • 6
20
votes
3 answers

Java - Simple way to put LinkedHashMap keys/values into respective Lists?

I have a LinkedHashMap < String, String > map . List < String > keyList; List < String > valueList; map.keySet(); map.values(); Is there an easy way to populate keyList from map.keySet() and valueList from map.values(), or do I have to iterate?
user375566
20
votes
1 answer

Converting a collection to Map by sorting it using java 8 streams

I have a list that I need to custom sort and then convert to a map with its Id vs. name map. Here is my code: Map map = new LinkedHashMap<>(); list.stream().sorted(Comparator.comparing(Building::getName)).forEach(b->…
Mohammad Adnan
  • 6,527
  • 6
  • 29
  • 47
19
votes
3 answers

equivalent LinkedHashmap in C++?

I have a Java program that I want to convert it to C++. So, there is a Linkedhashmap data structure used in the Java code and I want to convert it to C++. Is there an equivalent datatype for LinkedHashmap in C++? I tried to use std::unordered_map,…
emadalamoudi
  • 357
  • 1
  • 2
  • 12
1
2
3
46 47