Q:

List of Strings to hashmap using Streams

I have a "," separated String array like this
a b c d,
f b h j,
l p o i,

I would like this to be converted to a Hashmap like
HashMap<String, List<String>> such that second element in list (delimited by space becomes key and the 3rd element becomes value)
So,
This should become
b -> c,h
p -> o

I want to use Streams API and I think this is the way to go:
List<String> entries = new ArrayList<>();
HashMap<String, List<String>> map = new HashMap<>();

HashMap<String, List<String>> newMap = entries.stream()
    .collect(line -> {
        if (map.contains(line.split(" ")[1])) {
            // Get existing list and add the element
            map.get(line.split(" ")[1].add(line.split(" ")[1]));
        } else {
            // Create a new list and add
            List<String> values = new ArrayList<>();
            values.add(line.split(" ")[1]);
            map.put(line.split(" ")[0], values);
        }
    });

Is there any better way?  How exactly should I return Hashmap from collect function? 

A:

You can use the Collectors.groupingBy as shown below to group the inputs (follow the inline comments):
String[] inputs = {"a b c d,", "f b h j,", "l p o i,"};
Map<String, List<String>> results =  
     Arrays.stream(inputs).map(s -> s.split(" ")).//splt with space
     collect(Collectors.groupingBy(arr -> arr[1], // Make second element as the key
         Collectors.mapping(arr -> arr[2], // Make third element as the value
                            Collectors.toList())));//collect the values to List
 System.out.println(results);

Output:
{p=[o], b=[c, h]}

I suggest you read the API here to understand how Collectors.groupingBy along with Collectors.mappingworks.