I have an Array
and want to perform some matching on it's element.
I came to know that it could be done in two ways in java 8
:
String[] alphabet = new String[]{"A", "B", "C"};
anyMatch :
Arrays.stream(alphabet).anyMatch("A"::equalsIgnoreCase);
findAny :
Arrays.stream(alphabet).filter("a"::equalsIgnoreCase)
.findAny().orElse("No match found"));
As I can understand both are doing the same work. However, I could not found which one to prefer?
Could someone please make it clear what is the difference between both of them.