android - 比较 Android 中的两个 List<String> 值

标签 android string list equals

亲爱的,我正在比较 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/

相关文章:

Python将文本拆分为列表

java - 方法 toArray() 不适用于列表

android - 应用内结算接收者权限

android - 将数据发送到我的(主屏幕)小部件

字符串处理

android - 使用不同的方法从资源访问外部字符串有什么区别?

java - 比较时间戳时,年份转到 1970

java - android - 动态切换textView中的字符串

c# - CSV行拆分成字符串数组问题

Python (2.7.13) - 我有一个看起来像数组的字符串