亲爱的,我正在比较 android 中的两个列表,如果两个值相同并且它返回 true 很好,但我想知道列表字符串之间有多少值是正确的,如果它不匹配如何实现这个帮助受到赞赏。下面是我的代码。
List<String> list1 = new ArrayList<String>(i1.values());
///list 1 = [-ful; to be full of; play; playful; full of play]
List<String> acct_Rte_Cdes_A = Arrays.asList(result) ;
///acct_Rte_Cdes_A = [-ful; to be full of; play; playful; full of play]
if (list1.equals(acct_Rte_Cdes_A)) {
// do what you want to do if the string is there
//System.out.println("True");
} else {
System.out.println("False");
}
最佳答案
使用Collection#retainAll()
.喜欢
List<Integer> common = new ArrayList<Integer>(listA);
common.retainAll(listB);
// common now contains only the elements which are contained in listA and listB.
因此您可以检查大小是否大于 0,这意味着某些元素是常见的。 common
会说明哪些是常见元素。
关于android - 比较 Android 中的两个 List<String> 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17060400/