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. linux小白成长之路8————访问Docker中的mysql

    [内容指引] 本篇实战演示如何操作Docker中的mysql数据库,包含以下五个知识点: 登录容器: 登录mysql: 运行SQL指令创建数据库: 退出mysql: 退出容器: 1.登录容器 我们在上 ...

  2. Git常用命令(二)------ 远程库操作

    本文总结自廖雪峰网站. Git支持多种协议,git://使用ssh协议,速度最快,也可使用https等协议. 对远程库操作: 推送: 1.先远程建立一个Repo库,f 2.远程和本地关联: git r ...

  3. Leetcode 15——3Sum

    Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all un ...

  4. MySQL之连接查询

    主要是多表查询和连接查询

  5. 高级软件工程2017第6次作业——团队项目:Alpha阶段综合报告

    1.版本测试报告 1.1在测试过程中总共发现了多少Bug?每个类别的Bug分别为多少个? Bug分类 Bug内容 Fixed 编辑博文时改变文字格式会刷新界面 Can't reproduced 无 N ...

  6. bug终结者 团队作业第一周

    bug终结者 团队作业第一周 小组组员及人员分工 小组成员 组长: 20162323 周楠 组员: 20162302 杨京典 20162322 朱娅霖 20162327 王旌含 20162328 蔡文 ...

  7. Cocoapods最全完整使用教程

    什么是cocoapods cocoapods是库管理工具. cocoapods的用途 解决库之间的依赖关系.如前文所述: 一个开源的项目可能是另一个项目的基础, A依赖B, B依赖C和D, D又依赖E ...

  8. linux 下 nc 命令的使用

    netcat被誉为网络安全界的'瑞士军刀',一个简单而有用的工具,透过使用TCP或UDP协议的网络连接去读写数据.它被设计成一个稳定的后门工具,能够直接由其它程序和脚本轻松驱动.同时,它也是一个功能强 ...

  9. ajax中设置contentType: “application/json”的作用

    最近在做项目交互的时候,刚开始向后台传递数据返回415,后来百度添加了 contentType:"application/json"之后返回400,然后把传输的数据格式改为json ...

  10. 前端之HTML内容

    一.HTML介绍 1.Web服务本质 当我们在浏览器中输入一个url后打开一个页面这个过程实质是一个网络编程中的sockt服务端接受指令并发送指令的一个过程.本质顺序是: 浏览器发请求——>HT ...