package com.compare.test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class ListTest {
public static List<Integer> createList1(){
List<Integer> list=new ArrayList<Integer>();
list.add(1);
list.add(2);
list.add(3);
list.add(4);
list.add(5);
list.add(6);
return list;
}
public static List<Integer> createList2(){
List<Integer> list=new ArrayList<Integer>();
list.add(7);
list.add(8);
list.add(9);
list.add(4);
list.add(5);
list.add(6);
return list;
}
public static List<Integer> combine(List<Integer> list1,List<Integer> list2){
List<Integer> list=new ArrayList<Integer>(list1);
System.out.println("list1:");
printList(list);
list.removeAll(list2);
System.out.println("list1-list2:");
printList(list);
list.addAll(list2);
System.out.println("list1+list2:");
printList(list);
Collections.sort(list);
printList(list);
return list;
}
public static void printList(List<Integer> list){
System.out.println("List输出如下:");
for (int i = 0; i < list.size(); i++) {
int j=list.get(i);
System.out.println(j);
}
}
public static void main(String[] args) {
List<Integer> list1=createList1();
List<Integer> list2=createList2();
List<Integer> list=combine(list1, list2);
//printList(list);
}
}

合并两个list,不包含重复的对象的更多相关文章

  1. 【转】合并两个List并去掉重复项

    原文:https://my.oschina.net/jack90john/blog/1493170 工作中很多时候需要用到合并两个List并去除其中的重复内容.这是一个很简单的操作,这里主要是记录一下 ...

  2. leetcode350之实现求解两数组交集(包含重复元素)

    给定两个数组,编写一个函数来计算它们的交集. 说明: 输出结果中每个元素出现的次数,应与元素在两个数组中出现的次数一致. 我们可以不考虑输出结果的顺序 def binarySearch(nums, t ...

  3. [LeetCode] Contains Duplicate III 包含重复值之三

    Given an array of integers, find out whether there are two distinct indices i and j in the array suc ...

  4. 算法练习之x的平方根,爬楼梯,删除排序链表中的重复元素, 合并两个有序数组

    1.x的平方根 java (1)直接使用函数 class Solution { public int mySqrt(int x) { int rs = 0; rs = (int)Math.sqrt(x ...

  5. 算法练习之合并两个有序链表, 删除排序数组中的重复项,移除元素,实现strStr(),搜索插入位置,无重复字符的最长子串

    最近在学习java,但是对于数据操作那部分还是不熟悉 因此决定找几个简单的算法写,用php和java分别实现 1.合并两个有序链表 将两个有序链表合并为一个新的有序链表并返回.新链表是通过拼接给定的两 ...

  6. (转载)按行合并两个sql的查询结果

    (转载)http://blog.csdn.net/wxwstrue/article/details/6784774 Union all join 是平行合并 为水平连接 Union all 是垂直合并 ...

  7. [LeetCode] Contains Duplicate 包含重复值

    Given an array of integers, find if the array contains any duplicates. Your function should return t ...

  8. 剑指Offer面试题:16.合并两个排序的链表

    PS:这也是一道出镜率极高的面试题,我相信很多童鞋都会很眼熟,就像于千万人之中遇见不期而遇的人,没有别的话可说,唯有轻轻地问一声:“哦,原来你也在这里? ” 一.题目:合并两个排序的链表 题目:输入两 ...

  9. LeetCode 219. Contains Duplicate II (包含重复项之二)

    Given an array of integers and an integer k, find out whether there are two distinct indices i and j ...

随机推荐

  1. class 选择器

    class 选择器 1.class 选择器用于描述一组元素的样式,class 选择器有别于id选择器,class可以在多个元素中使用. 2.class 选择器在HTML元素中以class属性(即cla ...

  2. 漫谈Java IO之 NIO那些事儿

    前面一篇中已经介绍了基本IO的使用以及最简单的阻塞服务器的例子,本篇就来介绍下NIO的相关内容,前面的分享可以参考目录: 网络IO的基本知识与概念 普通IO以及BIO服务器 NIO的使用与服务器Hel ...

  3. Beta No.1

    一.今日任务 重新熟悉整体项目 对整个项目在未来的beta冲刺中进程有一个合理的规划 由于我们送出的是一个负责前端的成员,引入的也是一个负责前端工作的女生,(女生做起美工比起男生更加得心应手吧)所以我 ...

  4. Beta冲刺集合

    1.Day1 http://www.cnblogs.com/bugLoser/p/8075868.html 2.Day2 http://www.cnblogs.com/bugLoser/p/80758 ...

  5. 数字是否可以被3和5同时整除,use if and % (21.9.2017)

    #include <stdio.h> int main(){ int a; //a是所输入的数字 printf("输入数字: "); scanf("%d&qu ...

  6. 201621123057 《Java程序设计》第8周学习总结

    1. 本周学习总结 思维导图归纳总结集合相关内容. 2. 书面作业 1. ArrayList代码分析 1.1 解释ArrayList的contains源代码 ArrayList是允许重复的,但当用它来 ...

  7. 利用flask 实现简单模版站

    from flask import Flask,render_template from flask import request app = Flask(__name__) @app.route(' ...

  8. Node入门教程(1)目录

    aicoder.com 全栈实习之简明 Node 入门文档 aicoder.com 线下实习: 不 8000 就业,不还实习费. 如果需要转载本文档,请联系老马,Q: 515154084 JS基础教程 ...

  9. 新概念英语(1-11)Is this your shirt ?

    Is this your shirt?Whose shirt is white? A:Whose shirt is that? Is this your shirt, Dave? Dave:No si ...

  10. android- 远程调试

    最近由于要在另外一台android设备上调试代码,在本机PC上查看其log.两台机器离的比较远, 无法用usb直接连接,于是在网上找了很多资料,最找使用adb connect方法解决了该问题.解决过程 ...