[Solved] Adding an element into a HashSet inside a HashMap Java [closed]


As @AndyTurner said in a comment:

fields[1] is a String, not a HashSet<String>. You can build the latter using new HashSet<>(Arrays.asList(fields[1])).

But there are other issues with this snippet too. It would be better to rewrite like this, pay close attention to every little detail that I changed:

private Map<String, Set<String>> userBusiness = new HashMap<>();

...

String[] fields = output.split("\t");
userBusiness.put(fields[0], new HashSet<>(Collections.singletonList(fields[1])));

2

solved Adding an element into a HashSet inside a HashMap Java [closed]