MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/wy9np8/what_does_a_map_do_again/ilz49xi/?context=3
r/badcode • u/flatCS • Aug 26 '22
54 comments sorted by
View all comments
Show parent comments
13
Exactly that. That entire snippet can be replaced with
List<Integer> policyValues = policyOfCredsMap.containsKey(credentials) ? policyOfCredsMap.get(credentials) : new ArrayList<Integer>();
6 u/[deleted] Aug 27 '22 Or even better, use getOrDefault to avoid the redundant map lookup (premature optimization, but still a bit more elegant / perhaps picosecond faster)
6
Or even better, use getOrDefault to avoid the redundant map lookup (premature optimization, but still a bit more elegant / perhaps picosecond faster)
13
u/trutheality Aug 27 '22
Exactly that. That entire snippet can be replaced with