Skip to content

Tag: dictionary

Adding values to Map from a File

I want to iterate through a file that has key/value pairs and put them into a Map. The file contains values like so: Here is my code: The problem I am having is that the Map called instructions is not adding new values from the file, it stops at size 3, not sure why. Would appreciate some help here. Thanks!

Query did not return a unique result

This is the query I have written: This is the output I am getting from the database: id versions 101 0.0 101 1.0 101 2.0 101 3.0 In my application, I am storing this result in but it gives an error saying “query did not return a unique result” How can I store this result? which data structure could I

Get the last element of each entry in a LinkedHashMap?

I have a map and I want to extract the last value for each key from that map, but I can’t get it: Extract: i.e. the last NUM entries for each key Answer You can use reduce to extract the last value from Map<String,String> and then collect them using toMap into LinkedHashMap to save the insertion order But as a

Java: join the values of a map containing sets

Consider the following pseudo Map<String, Set<String>>: What is the best way to join the value Sets into a single Set (above example should be [“A”, “B”, “C”, “D”]). The order of the resulting set does not matter. I know that I can to something like this: But it feels kind of ugly and I’m wondering if there is a better