Given a list of numbers ( fixed list) Now given any other list, how can you efficiently find out if

网友投稿 544 2022-09-06

Given a list of numbers ( fixed list) Now given any other list, how can you efficiently find out if

Given a list of numbers ( fixed list) Now given any other list, how can you efficiently find out if

Given a list of numbers ( fixed list) Now given any other list, how can you efficiently find out if there is any element in the second list that is an element of the first list (fixed list).

import java.util.ArrayList; import java.util.List;public class Duplicate { public static void main(String args[]) { List list1 = new ArrayList(); List list2 = new ArrayList(); for (int i = 0; i < 5; i++) list1.add((int) (Math.random() * 10)); for (int i = 0; i < 10; i++) list2.add((int) (Math.random() * 10)); for (int i = 0; i < list1.size(); i++) { System.out.print(list1.get(i) + " "); } System.out.println(); for (int j = 0; j < list2.size(); j++) { System.out.print(list2.get(j) + " "); } System.out.println(); for (int i = 0; i < list2.size(); i++) { for (int j = 0; j < list1.size(); j++) { if (list1.get(j) == list2.get(i)) { System.out.print(list2.get(i) + " "); } } } }}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:switch button
下一篇:mysql数据库备份和还原(mysql数据库备份与还原)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~