I have a list like this
[A-Apple.txt,B-Ball.txt,A-Axe.txt,B-Box.txt]
From this I want to create a map like the following:
{A=[A-Apple.txt,A-Axe.txt], B= [B-Ball.txt, B-Box.txt]
I have tried with
Map<String,List<String>> inputMap = new HashMap<>();
inputFCSequenceFileList.forEach(value ->{
List newList = new ArrayList();
newList.add(value);
inputMap.put(value.split("-")[0], newList);
}
);
But not getting the expected value. I am getting only the last element. And if I move the list creation outside of the foreach loop, then I am getting all the values.