User_67128 :
I have a HashMap<Integer, List<Integer>>
"sq_diff
" and I am trying to update an entry.
I tried:
List<Integer> values = sq_diff.get(diff);
values.add(c);
values.add(d);
sq_diff.put(diff, values);
and
sq_diff.get(diff).add(c);
sq_diff.get(diff).add(d);
and
sq_diff.computeIfPresent(diff, (k, v) -> v.add(c);
sq_diff.computeIfPresent(diff, (k, v) -> v.add(d);
None of them working:
Exception in thread "main" java.lang.UnsupportedOperationException
The map contains an entry of "diff
"
Highly appreciated if you can indicate problems on each of them.
abhimanyue :
Try this,
List<Integer> values = new ArrayList<>(Arrays.asList(c, d));
sq_diff.put(diff, values);
instead of
sq_diff.put(diff, Arrays.asList(c, d));
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=419054&siteId=1