To check the if List of string contains at least one uppercase word, we are using stream api.
- First, we take a Arraylist object with String type parameter.
- Now get the Stream data from List using listString.stream() method.
- Stream anyMatch() is a method that returns true if any element in the stream matches a given Predicate, and false otherwise.
- Inside anyMatch() method, first we find the uppercase word from e.toUpperCase() method. after we compare this word to list of string data from equals() method.
- Print the Boolean type of output status.
import java.util.Arrays;
import java.util.List;
public class MatchTest {
public static void main(String[] args) {
List<String> listString = Arrays.asList("hibernate ", "JAVA", "spring", "servlet", "jsp", "123");
boolean status = listString.stream().anyMatch(e -> e.equals(e.toUpperCase()));
System.out.println("Uppercase word is there :- " + status);
}
}
Output :-
Uppercase word is there :- true