I'm trying to find a matching value in a Map and if found, I need to throw an IllegalArgumentException. My code is as follows:
final String stringToBeMatched = "someRandomString";
map.values()
.stream()
.filter(a -> stringToBeMatched == a.getField())
.findAny()
.ifPresent(a -> throw new IllegalArgumentException());
I get a syntax error on token "throw". I'm not sure where I'm going wrong.