//set集合去重,不改变原有的顺序
public static void pastLeep1(List<String> list){
System.out.println("list = [" + list.toString() + "]");
List<String> listNew=new ArrayList<>();
Set set=new HashSet();
for (String str:list) {
if(set.add(str)){
listNew.add(str);
}
}
System.out.println("listNew = [" + listNew.toString() + "]");
} //遍历后判断赋给另一个list集合
public static void pastLeep2(List<String> list){
System.out.println("list = [" + list.toString() + "]");
List<String> listNew=new ArrayList<>();
for (String str:list) {
if(!listNew.contains(str)){
listNew.add(str);
}
}
System.out.println("listNew = [" + listNew.toString() + "]");
} //set去重
public static void pastLeep3(List<String> list){
System.out.println("list = [" + list + "]");
Set set = new HashSet();
List<String> listNew=new ArrayList<>();
set.addAll(list);
listNew.addAll(set);
System.out.println("listNew = [" + listNew + "]");
} //set去重(缩减为一行)
public static void pastLeep4(List<String> list){
System.out.println("list = [" + list + "]");
List<String> listNew=new ArrayList<>(new HashSet(list));
System.out.println("listNew = [" + listNew + "]");
} //去重并按自然顺序排序
public static void pastLeep5(List<String> list){
System.out.println("list = [" + list + "]");
List<String> listNew=new ArrayList<>(new TreeSet<String>(list));
System.out.println("listNew = [" + listNew + "]");
}

List的五种去重方式的更多相关文章

  1. iOS开发中数组常用的五种遍历方式

    随着iOS的不断发展,apple也不断推出性能更高的数组遍历方式,下面将对熟悉的五种遍历方式进行列举. 首先定义一个数组,并获取数组长度 NSArray *array=@[",]; NSIn ...

  2. Spring事务Transaction配置的五种注入方式详解

    Spring事务Transaction配置的五种注入方式详解 前段时间对Spring的事务配置做了比较深入的研究,在此之间对Spring的事务配置虽说也配置过,但是一直没有一个清楚的认识.通过这次的学 ...

  3. CacheConcurrencyStrategy五种缓存方式

    CacheConcurrencyStrategy有五种缓存方式:  CacheConcurrencyStrategy.NONE,不适用,默认  CacheConcurrencyStrategy.REA ...

  4. JS中的五种去重方法

    JS中的五种去重方法 第一种方法: 第二种方法:  第三种方法: 第四种方法: 第五种方法:优化遍历数组法 思路:获取没重复的最右一值放入新数组 * 方法的实现代码相当酷炫,* 实现思路:获取没重复的 ...

  5. IPC五种通讯方式

    IPC五种通讯方式 1.管道:速度慢,容量有限,只有父子进程能通讯 2.FIFO:任何进程间都能通讯,但速度慢 3.消息队列:容量受到系统限制,且要注意第一次读的时候,要考虑上一次没有读完数据的问题 ...

  6. LFU五种实现方式,从简单到复杂

    前言 最近刷力扣题,对于我这种 0 基础来说,真的是脑壳疼啊.这个月我估计都是中等和困难题,没有简单题了. 幸好,力扣上有各种大牛给写题解.看着他们行云流水的代码,真的是羡慕不已.让我印象最深刻的就是 ...

  7. JS 跨域问题常见的五种解决方式

    一.什么是跨域? 要理解跨域问题,就先理解好概念.跨域问题是由于javascript语言安全限制中的同源策略造成的. 简单来说,同源策略是指一段脚本只能读取来自同一来源的窗口和文档的属性,这里的同一来 ...

  8. Flex页面跳转的五种实现方式

    Flex页面跳转有很多值得学习的地方,本文向大家介绍一下Flex页面跳转的几种方式,主要包括五种方式,这里为大家一一介绍. AD:   在学习Flex的过程中,你可能会遇到Flex页面跳转的概念,这里 ...

  9. JavaScript五种继承方式详解

    本文抄袭仅供学习http://www.ruanyifeng.com/blog/2010/05/object-oriented_javascript_inheritance.html 一. 构造函数绑定 ...

随机推荐

  1. linq join 左连接 leftjoin 多个on条件 where 条件

    var haveChange = from newScore in newScoreList join oldScore in oldScoreList on new{newScore.ExamId, ...

  2. win10专业版激活方法

    slmgr.vbs /upk 此时弹出窗口显未“已成功卸载了产品密钥”. slmgr /ipk W269N-WFGWX-YVC9B-4J6C9-T83GX 弹出窗口提示:“成功的安装了产品密钥”. s ...

  3. MyBatis之one2one与one2many

    <!--顾客信息表,其中一个顾客对应一个国家,一个顾客对应多个订单--> <resultMap id="customerResultMap" type=" ...

  4. LNMP架构介绍 MySQL安装 PHP安装 Nginx介绍

  5. 使用vi时提示 write error in swap file

    今天使用vi 命令时,提示write error in swap file 查了下原因,磁盘空间不够 df -h 使用 rm -rf 文件名 ,删除不用的 使用 echo "" & ...

  6. java http post上传文件

    1.上传接口 @IgnoreToken @RequestMapping(value = "/upload/cpicFile", method = RequestMethod.POS ...

  7. 总结的比较好的OpenGL教程

    OpenGL Programming Guide(红宝书) http://www.glprogramming.com/red/ OpenGL Reference Manual(蓝宝书) http:// ...

  8. Go面向对象(三)

    go语言中的大多数类型都是值予以,并且都可以包含对应的操作方法,在需要的时候你可以给任意类型增加新方法.二在实现某个接口时,无需从该接口集成,只需要实现该接口要求的所有方法即可.任何类型都可以被any ...

  9. lua 根据函数名字符串来执行函数

    function myfunction(msg) print("this is msg fun " .. msg); end local fun =_G["myfunct ...

  10. 【RF库测试】Encode String To Bytes&Decode Bytes To String& should be string&should be unicode string &should not be string

    场景1:判断类型 r ${d} set variable \xba\xcb\xbc\xf5\xcd\xa8\xb9\xfd #核减通过 Run Keyword And Continue On Fail ...