Java Check Whether String Is Palindrome | Java 8 Stream NoneMatch Example | InterviewDOT

preview_player
Показать описание

Java Check Whether String Is Palindrome | Java 8 Stream NoneMatch Example | InterviewDOT

The stream noneMatch() method works just opposite to the anyMatch() method, it returns true if none of the stream elements match the given predicate, it returns false if any of the stream elements matches the condition specified by the predicate.

Java 8 Stream allMatch, anyMatch and noneMatch methods are applied on stream object that matches the given Predicate and then returns boolean value. allMatch() checks if calling stream totally matches to given Predicate, if yes it returns true otherwise false. anyMatch() checks if there is any element in the stream which matches the given Predicate. noneMatch() returns true only when no element matches the given Predicate.

noneMatch() method is a method which takes argument as a Predicate and if none of element of stream matches the given Predicate, then it returns true otherwise false.

To check if a string is a palindrome or not, a string needs to be compared with the reverse of itself.

Consider a palindrome string: radar
Рекомендации по теме