Skip to content
Advertisement

Tag: hashmap

Check if last taken Map element is last

Faced a problem where I need to put elements in two different Maps and after go through all of them and put if condition on the last element of the last Map. Here I have code I’ve tried: Now I have two for loops where I want to check if both for loops have last element right now: I have

Java invert a map

I need to invert an original map. which type is <Integer, String>, like {1 = A, 2 = A, 3 = B….}. I want to create a new map which is String to ArrayList because if 1 = A, and 2 = A, than I want to have something like this: A = [1, 2]. So how can I do

ResultSet to HashMap

I am trying to pass the output of a ResultSet to Java HashMap. While the Output1 is showing all the records(from the DB). The put command only takes the last value from the ResultSet in. Output1: Output2: How do I make the put command to iterate over the results from the ResultSet? Answer All your IDs are identical (502332262), and

How to extract a HashMap from a Java heap dump

I have a Java heap dump generated using jmap. This contains a HashMap which I need to extract into a text format (CSV would be fine). The HashMap is fairly large so I need a scripted solution. Using JVisualVM I can find the HashMap. However, there doesn’t seem to be a way to export its data. After some experimentation I

Why does clear hashmap method clears added map in array list

I’m trying to reuse same HashMap like in example bellow to populate list. First I put some values in the map, add map to the list and then clear map in order to put again new values and add second set of values in the list and so on… But, it seems that clear() method also delete values previously added

Java – Write hashmap to a csv file

I have a hashmap with a String key and String value. It contains a large number of keys and their respective values. For example: I would like to write this hashmap to a csv file such that my csv file contains rows as below: I tried the following example here using the supercsv library: http://javafascination.blogspot.com/2009/07/csv-write-using-java.html. However, in this example, you

Convert String to Hashmap in Java

I have the following string: I want to convert it back to hashmap. I tried the following code below but the problem is that it can’t convert the string with spaces. It outputs something like this: I think it has something to do with the regex. Help! Thanks. Answer Something like this will work for you :

Multiplying Values of Two HashMaps

If I have two HashMaps, hm1 and hm2, how can I iterate through the two and multiply the two values together at each point in the two HashMaps and sum the total? They are both ordered identically, so I don’t need to worry about the keys, just the values. The data is in the form then I want to do

Advertisement