如何在java中检查字符串数组的字符串?

问题描述:

HI我想用一个字符串数组检查一个字符串值。我使用 contains()方法,但它区分大小写。例如:

HI I want to check one string value with an array of strings. I am using the contains() method, but it is case sensitive. For example:

String str="one";
String [] items= {"ONE","TWO","THREE"};

str.contains(items); // it is returning false.

现在的问题是如何检查该字符串?

Now the question is how to check that string ?

任何人都可以帮助我吗?

can anyone help me?

提前感谢

项目是否包含 str ?并且不区分大小写。因此遍历数组:

You probably want to know if items contain str? And be case-insensitive. So loop through the array:

boolean contains = false;
for (String item : items) {
    if (str.equalsIgnoreCase(item)) {
        contains = true;
        break; // No need to look further.
    } 
}