Prabu Prabu - 4 months ago 19
Java Question

Java - contains check all items in an arraylist meet a condition

myArrayList = {"Method and apparatus","system and method for the same","drive-modulation method"," METHOD FOR ORTHOGONAL"}


How can i check if all the Items (myArrayList) contains a word "method" (irrespective of case)

boolean method return
true
if all the items contain the word, else its
false

Answer

Iterate and use contains. Remove the or conditions if you want case specific.

   public static boolean isListContainMethod(List<String> arraylist) {
    for (String str : arraylist) {
        if (!str.toLowerCase().contains("method")) {
            return false;
        }
    }
    return true;
}