-1

I have a

MultiValueMap<String, String> map = new LinkedMultiValueMap<>();

The type of value is a list of strings:

List<String> valueList = map.get('key');

How can i search through this map (through all the valueLists within this map) and get all the values which startsWith 'xy' in a list back?

I hope the question is clear.

I have tried this, but no success:

  map
    .entrySet()
    .stream()
    .filter(e-> e.getValue().stream().filter(value -> value.startsWith(searchString)))
    .collect(Collectors.toList());

I get this error: Stream cannot be converted to boolean

akcasoy
  • 6,497
  • 13
  • 56
  • 100

1 Answers1

1

If I understood your problem correctly:

map.values()
    .stream()
    .flatMap(List::stream)
    .filter(x -> x.startsWith(searchString))
    .collect(Collectors.toList())
Eugene
  • 117,005
  • 15
  • 201
  • 306