检查的ArrayList&LT;串GT;包含一个字符串的一部分 [英] Check if ArrayList<String> contains part of a string
本文介绍了检查的ArrayList&LT;串GT;包含一个字符串的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
说我有一个ArrayList
Say I have an ArrayList:
<string1.4>
<string2.4>
<string3.4>
和我想返回ArrayList的第一个元素,当我说arrayList.containsSubString('字符串1');怎么会这样比通过每个 ArrayList的元素进行迭代
并检查是否字符串1
是一个子做其他该元素的字符串?
and I wish to return the the first element of the arrayList when I say arrayList.containsSubString('string1'); How could this be done other than iterating through each of the elements of the arrayList
and checking if string1
is a substring of that element string?
推荐答案
我能想到的唯一的办法就是做这样的事情:
The only way I can think of is doing something like:
strs.get(strs.indexOf(new Object() {
@Override
public boolean equals(Object obj) {
return obj.toString().contains(s);
}
}));
不知道是不是认为,虽然很好的做法。
Don't know if it is considered good practice though.
这篇关于检查的ArrayList&LT;串GT;包含一个字符串的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文