比较在Java 2列出 [英] compare 2 lists in java

查看:116
本文介绍了比较在Java 2列出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是从两个不同的数据库获取数据,并将其存储在java.util.List中

I am getting data from the two different databases and storing them in the java.util.List

Elements of database:1 
column 1                   column 2
**Investment Number**     Investment Name
123                         abcwe
124                         agsdf
454                         lkjcv
784                         ojncv
478                         hfdgh
852                         qweyu
745                         mmkty
201                         pbckl
560                         jklfg
741                         nbvbn 

将它们存储在list1的

storing them in list1

数据库的要素:2

column 1                   column 2
Investment Number     Property Number
123                         548
980                         743
454                         200
350                         357
478                         698
852                         223
745                         795
784                         213
341                         022
741                         900

将它们存储在list2中

storing them in list2

根据需要投资数进行比较,如果在列表2可用list1的投资数目则需要保持并丢弃等。

need to compare according to the Investment Numbers if Investment Number of list1 available in list2 then need to keep and discard others.

谢谢,

推荐答案

如果您有两个列表,你可以做到以下几点:

If you have two list, you can do the following:

List<Integer> list1 = new ArrayList<>(Arrays.asList(1, 5, 6, 7));
List<Integer> list2 = new ArrayList<>(Arrays.asList(5, 6, 7, 8, 9));
list1.retainAll(list2);
System.out.println("list1 = " + list1);

和其结果将是:

list1 = [5, 6, 7]

这篇关于比较在Java 2列出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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