Click here to Skip to main content
15,171,993 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a linked hashmap which contains these values:

```
LinkedHashMap<String,String> map= new LinkedHashMap<>();
map.put("A101","2020_1.0");
map.put("A101","2020_3.0");
map.put("A101","2020_2.0");
map.put("A102","2020_2.0");
map.put("A102","2020_1.0");
```

I need to get:
A101 2020_3.0 and
A102 2020_2.0


What I have tried:

not able to solve. Tried substring, replaceall method but not able to do. need help
Posted
Comments
Richard MacCutchan 20-Oct-21 4:51am
   
You cannot use the same Key for multiple values. If you list the entries of your map you will find only a single entry for each of your keys.
Sachin Singh 2021 20-Oct-21 6:56am
   
ArrayList<string,string> list= new ArrayList<>();
list.put("A101","2020_1.0");
list.put("A101","2020_3.0");
list.put("A101","2020_2.0");
list.put("A102","2020_2.0");
list.put("A102","2020_1.0");

Now how can i get A101 2020_3.0 and A102 2020_2.0
Richard MacCutchan 20-Oct-21 7:28am
   
You will need to search for the items that match your requirements.
Sachin Singh 2021 20-Oct-21 8:12am
   
can you let the logic for that?
Richard MacCutchan 20-Oct-21 8:24am
   
I have no idea what the basic problem is, or how you will decide which items to search for. Where does the information come from that you use to build your lists? Where does the information come from that you use to decide which items to search for? It may be that a simple array list is not the best collection type to solve your problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900