#Got a hashMap <String,List<String>>, how do I check if any of the existing Lists contains an item?

1 messages · Page 1 of 1 (latest)

proven cragBOT
#

<@&987246399047479336> please have a look, thanks.

proven cragBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

fringe geyser
#

the question is poorly prased. you cannot get a certain value from a map without the key. the key seams to be a string. so a string is mapped to a list of strings. correct?

frozen fox
#

Yep

#

I just spotted what I needed, the .containsValue() method, sorry for bothering ya

proven cragBOT
#

Closed the thread.

feral elm
#

.containsValue() will require you to pass a List

#

and the list you pass will be matched exactly against the lists in a map

#

which is probably not what you want

frozen fox
#

efficiency is ignored at this point of time, just need to do it, already finished it up. Isnt this thread closed or deleted at this point tho?

feral elm
#

it's not about efficiency

#

but, sure

proven cragBOT
#

Closed the thread.

frozen fox
feral elm
#

if you don't need to pinpoint which exact list contains foo, you can use map.values().stream().flatMap(Collection::stream).anyMatch(foo::equals)

frozen fox
#

what does everything past .stream() do?

feral elm
#

if you're not comfortable with streams, just do a simple iterational approach instead

frozen fox
#

damn I suck, how does that approach work? some for-each loops?

feral elm
#

yeah, just iterate all values in a map

#

and for each list, do a contains() check

frozen fox
#

thanks