如何在java中检查字符串数组的字符串? [英] How to check string with array of strings in java?

查看:172
本文介绍了如何在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.
    } 
}

这篇关于如何在java中检查字符串数组的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆