I have an ArrayList of String Array and the 2nd element of every String Array contains a name. I want to create a Map where it's Key is the name and Value is an ArrayList of all String Array which has the name.
How can I achive this in Java?
Input: ArrayList<String[]>
{"1", "NameABC", "somestring"}
{"2", "NameDEF", "somestring"}
{"3", "NameDEF", "somestring"}
{"4", "NameABC", "somestring"}
{"5", "NameXYZ", "somestring"}
Output: Map<String, ArrayList<String[]>
Key = NameABC, Value = ArrayList of String[] where every String[] has NameABC
Key = NameXYZ, Value = ArrayList of String[] where every String[] has NameXYZ
I've tried using stream.collect(Collectors.toMap()) but I can't figure out how to achieve the proper output.
stream.collect(Collectors.toMap())? What was wrong with your attempt?recordcan be defined locally, within a method.