I have a map like below:

```
Map<String, String> map1 = new HashMap<String, String>();

```

and the contents are:

```
ID_1 -> ID_2
------------
100 -> 10
200 -> 20
300 -> 30

```

Based on the value of ID\_2 I have to query an oracle table and get a code value corresponding to each entry:

```
ID_1 -> ID_2 -> code
--------------------
100 -> 10 -> 8
200 -> 20 -> 2
300 -> 30 -> 9

```

and then I will have to get the map1 sorted in ascending way by the code value i.e the result should be:

```
200 -> 20
100 -> 10
300 -> 30

```

I have thought of creating an intermediary map with `<ID_1, List<ID_2,code>>` as `<K,V>` and then sort using the code value and then get the final output.

Is there any shorter way to do so, like without using an intermediary map?