-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
  • 5,740
  • 12
  • 49
  • 90

1 Answers1

1

If I understood your problem correctly:

map.values()
    .stream()
    .flatMap(List::stream)
    .filter(x -> x.startsWith(searchString))
    .collect(Collectors.toList())
Eugene
  • 110,516
  • 12
  • 173
  • 277