Check if a list Contains a value - Java java.util

Java examples for java.util:List Value

Description

Check if a list Contains a value

Demo Code

//package com.java2s;
import java.util.List;

public class Main {
    public static boolean listContains(List<String> list, String valueToFind) {

        if (list == null || valueToFind == null) {
            return false;
        }/*from  ww  w  . j av a  2s.  c  o m*/
        for (String item : list) {
            if (item != null && item.equals(valueToFind)) {
                return true;
            }
        }
        return false;
    }
}

Related Tutorials