Prabu Prabu - 1 year ago 97
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
if all the items contain the word, else its

Answer Source

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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download