查找在Java中两个不同的数组列表对象少见,常见的所有元素 [英] Find the uncommon, common all elements from two different array list objects in java

查看:361
本文介绍了查找在Java中两个不同的数组列表对象少见,常见的所有元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从两个不同的非下令Java数组列表对象找到少见,常见的物品。我已阅读这些很多帖子,但无法找到一个合适的答案。

I am trying to find the uncommon, common items from two different non-ordered array list objects in java. I have already read many posts about these but could not find a proper answer.

第一个数组对象列表是从服务器获取存储数据。第二个数组对象列表存储在本地数据库中的数据。

The first array list objects stores the data that are fetched from the server. The second array list objects stores the local database data.

现在我试图找到在常见,不常见的都来自这两个数组列表元素。在这里,数组列表是由完全两种不同的模型类生成,但它们具有类似的性质。

Now I am trying to find the common, uncommon all elements from these two array lists. Here the array lists are generated from completely two different model classes but they have similar properties.

在平等的比较确实给共同的价值,但无法找到两个数组列表不凡的项目,当我把条件为!listA.id.equals(listB.id)。

The equal comparison does give the common value but can't find the uncommon items from the two array lists when i put the condition as "!listA.id.equals(listB.id)".

例如:

for(CustomStation user1 : localStationLists) {
                            for(CustomStation user2 : serverStationLists) {
                                if(user1.getStationId().equals(user2.getStationId())) {
                                    *//*if(!user1.getTitle().equals(user2.getTitle())) {
                                        resultList.add(user1);
                                    }*//*
                                    //System.out.println(" EQUAL St ids : " + user1);
                                    resultList.add(user2);
                                }
                                else{
                                    resultList1.add(user1);
                                }
                            }

所以,想着你们是否也有同样的问题?

So, thinking whether you guys are also having the same problems?

一直在试图为过去三天​​不同的方法,但已多次未能得到解决。

Have been trying for last three days with different approaches but have been failed repeatedly to get a solution.

推荐答案

我没有测试此code,但你可以试试这个:

I have not tested this code but you can try this:

for(CustomStation user1 : localStationLists) 
{
    boolean flag = false;
    for(CustomStation user2 : serverStationLists) 
    {
        if(user1.getStationId().equals(user2.getStationId())) 
        {
            if(!user1.getTitle().equals(user2.getTitle())) 
            {
                resultList.add(user1);
            }            
            resultList.add(user2);
            flag = true;
            break;
        }
    }

    if(flag == false)
    {
        resultList1.add(user1);
    }
}

这篇关于查找在Java中两个不同的数组列表对象少见,常见的所有元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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