I have a Map<String,Object>
which contains an element value of List<String>
Now I need to filter the latter and retrieve first value that contains @
.
The best I did was:
Map<String, Object> map = new HashMap<>();
map.put("alias", List.of("Mxxx", "fstarred@mymail.org"));
final Object obj = map.get("alias");
final List lst = (List) obj;
final Object output= lst.stream()
.filter(o -> ((String) o).contains("@"))
.findFirst()
.orElse(null);
however looks to much verbose and mostly requires:
- a final cast to String of output
- a cast for each object passed into filter
For the above issued, I tried .map(String.class::cast)
- After
lst.stream()
- After
filter(o -> ((String) o).contains("@"))
None of these approaches did work.
Any hints?