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.
Questions tagged [linkedhashmap]
703 questions
0
votes
1 answer
Cash register outputs string of denominations in which to give change. Input is purchase price and cash given
I don't know why when iterating through my linkedhashmap to find the smallest possible combination of denominations to give as change in this piece of code, when iterating through "Five pence", the program fails and gives an erroneous final…
0
votes
0 answers
How do I change the order of a map based on its values?
My program calculates the digit sums of all values entered into a text file. The entered values and their according digit sums are stored in a LinkedHashMap and they are in descending order (by their digit sum). Works as expected, so far.
If you…

HeartCore
- 49
- 5
0
votes
4 answers
search for a key value pair in a list of hash maps
I am reading two csv files containg a set of attributes
File 1 attributes = name, class, rollno,
File 2 attributes = rollno, city,town
I need to match the two files and for every matching rollno I have to append the File 2 attributes into File1…

ahaneo
- 25
- 1
- 2
- 5
0
votes
1 answer
How to transform a flattened LinkedHashMap to one that represents a hierarchy
I'm a Java newbie and I'm having problems conceptualizing how to solve the problem of trying to create a LinkedHashMap that represents some hierarchical data.
This is as far as I've gotten. In this example, I've got a LinkedHashMap that shows the…

fumeng
- 1,771
- 5
- 22
- 61
0
votes
1 answer
Scala mutable.LinkedHashMap: for-loop remove strange behavior
I have a mutable.LinkedHashMap and try to remove item in a for-loop. However, if remove occurs, the for-loop also stops.
scala> val a = mutable.LinkedHashMap[Int, Int](1->1, 2->2, 3->3)
# when no remove occurs, for-loop works as expected
scala> for(…

xiangl
- 13
- 2
0
votes
1 answer
Compare value according to key in LinkedHashMap to another LinkedHashMap using java
I have two linked hashmap (key - String, value = String[]) which got the same size and the same keys in both linked hashmaps, I want to be able to compare values according to the key, verifying values on one linked hashmap are equals to the same…

tupac shakur
- 658
- 1
- 12
- 29
0
votes
0 answers
0
votes
1 answer
How to parse xml file containing multiple tags using LinkedHashMap?
I want to build a parser to parse an XML file in Java.
As you can see in my code below I am using a LinkedHashMap to access the desired values First, Middle and Last.
My problem is that I have NameList tags containing multiple Person tags and the…
user9734003
0
votes
2 answers
How do I keep the longest lines in a file while maintaining the order in which they appear?
I am making an application which involves reading text files (.txt) and one of the requirements is to keep a N (where N is specified by the user) number of longest lines in the file while maintaining the order in which they appear within the…

Dhruv Mehta
- 1
- 1
0
votes
1 answer
Why do I get intermittent ConcurrentModificationExceptions in the constructor of LinkedHashMap?
A version of the static method append() below, is sometimes called simultaneously by various threads:
public class CMEDemo {
private static final Logger LOG = Logger.getLogger(CMEDemo.class.getName());
private static final String[]…

Charlweed
- 1,517
- 2
- 14
- 22
0
votes
3 answers
Change iteration order for a Map
How can I iterate over a Map in a specific desired order?
I currently have a HashMap and want to be able to define a specific iteration order. The order should be able to get changed by the user.
My first thought was to use a LinkedHashMap since…

Tigerware
- 3,196
- 2
- 23
- 39
0
votes
0 answers
Which implementation among the below is better for converting a ResultSet to a KeyVal Pair?
I have 2 pieces of running code to convert ResultSet data to List of a LinkedHashMap key value pair. I need suggestions on which one is a better implementation. Please note that the data that will be coming in is not really big.
private static…

Jitendra Singh
- 191
- 1
- 8
0
votes
1 answer
java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to java.lang.Comparable exception when trying sort a List
While trying to sort a list of WlMatch Type as in below code, I am seeing the exception:
java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to java.lang.Comparable
I tried using both comparable and comparator sort but resulted in…

Swarup Reddy
- 21
- 4
0
votes
4 answers
Using class Objects and its properties in Java Collections
I have a Class Class1 with 3 properties (prop1, prop2, prop3).
I have another Class Class2 with a Hashmap hashMap1.
I am using Class1 object in hashMap1 and inserting a value for prop1, prop2, prop3.
Class1
public class Class1
{
private String…

Nirav Pardiwala
- 109
- 1
- 1
- 4
0
votes
1 answer
Sort and Compare LinkedHashMap and fetch 3 elements
There is a Json which has many attributes named id, I have to sort that, then compare and then I have to fetch the recently added 3 Objects with id as an attribute.
restgetAllRecentOrders: fetches all the recent orders
List…

Lavish Khetan
- 59
- 1
- 10