数组包含()不区分大小写的查找? [英] Array contains() without case sensitive lookup?
本文介绍了数组包含()不区分大小写的查找?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以以某种方式告诉array.contains()方法不能使查找区分大小写?
列表<串GT;数据= Arrays.asList(
一,二,三); //大量条目(100+)data.contains(三);
解决方案
包含
只检查一个对象是否是列表present。所以,你不能做一个区分大小写的查找在这里,因为三是一个不同的对象比三。
有一个简单的方法来解决,这将是
公共布尔containsCaseInsensitive(字符串s名单,LT;弦乐→1){
对于(字符串字符串:L){
如果(string.equalsIgnoreCase(多个)){
返回true;
}
}
返回false;
}
然后
containsCaseInsensitive(三化,数据);
Can I somehow tell the array.contains() method to not make the lookup case sensitive?
List<String> data = Arrays.asList(
"one", Two", "tHRee"); //lots of entries (100+)
data.contains("three");
解决方案
contains
just check if an object is present in the List. So you can't do a case insensitive lookup here, because "three" is a different object than "Three".
A simple approach to solve this would be
public boolean containsCaseInsensitive(String s, List<String> l){
for (String string : l){
if (string.equalsIgnoreCase(s)){
return true;
}
}
return false;
}
and then
containsCaseInsensitive("three", data);
这篇关于数组包含()不区分大小写的查找?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文