1. 循环list中的所有元素然后删除重复

  1. public   static   List  removeDuplicate(List list)  {
  2. for  ( int  i  =   0 ; i  <  list.size()  -   1 ; i ++ )  {
  3. for  ( int  j  =  list.size()  -   1 ; j  >  i; j -- )  {
  4. if  (list.get(j).equals(list.get(i)))  {
  5. list.remove(j);
  6. }
  7. }
  8. }
  9. return list;
  10. }

2. 通过HashSet踢除重复元素

  1. public   static   List  removeDuplicate(List list)  {
  2. HashSet h  =   new  HashSet(list);
  3. list.clear();
  4. list.addAll(h);
  5. return list;
  6. }

在groovy中当然也可以使用上面的两种方法, 但groovy自己提供了unique方法来去除重复数据

  1. def list = [1, 2, 3, 2, 4, 1, 5]
  2. list.unique()  // [1, 2, 3, 4, 5]

Judge的更多相关文章

  1. Gym 101102C---Bored Judge(区间最大值)

    题目链接 http://codeforces.com/gym/101102/problem/C problem description Judge Bahosain was bored at ACM ...

  2. NOJ 1074 Hey Judge(DFS回溯)

    Problem 1074: Hey Judge Time Limits:  1000 MS   Memory Limits:  65536 KB 64-bit interger IO format: ...

  3. 【教程】如何正确的写一个Lemon/Cena的SPJ(special judge)

    转自:http://www.cnblogs.com/chouti/p/5752819.html Special Judge:当正确的输出结果不唯一的时候需要的自定义校验器 首先有个框架 #includ ...

  4. 九度 Online Judge 之《剑指 Offer》一书相关题目解答

    前段时间准备华为机试,正好之前看了一遍<剑指 Offer>,就在九度 Online Judge 上刷了书中的题目,使用的语言为 C++:只有3题没做,其他的都做了. 正如 Linus To ...

  5. UVa Online Judge 工具網站

    UVa Online Judge 工具網站   UVa中译题uHuntAlgorithmist Lucky貓的ACM園地,Lucky貓的 ACM 中譯題目 Mirror UVa Online Judg ...

  6. [swustoj 1021] Submissions of online judge

    Submissions of online judge(1021) 问题描述 An online judge is a system to test programs in programming c ...

  7. HDOJ/HDU 1073 Online Judge(字符串处理~)

    Problem Description Ignatius is building an Online Judge, now he has worked out all the problems exc ...

  8. write a macro to judge big endian or little endian

    Big endian means the most significant byte stores first in memory. int a=0x01020304, if the cpu is b ...

  9. UVA 489-- Hangman Judge(暴力串处理)

     Hangman Judge  In ``Hangman Judge,'' you are to write a program that judges a series of Hangman gam ...

  10. 杭州电子科技大学Online Judge 之 “确定比赛名次(ID1285)”解题报告

    杭州电子科技大学Online Judge 之 "确定比赛名次(ID1285)"解题报告 巧若拙(欢迎转载,但请注明出处:http://blog.csdn.net/qiaoruozh ...

随机推荐

  1. XSLT 处理程序是如何工作的

    与 JSP.PHP 和其他 Web 开发语言的比较 在本文中,Benoit Marchal 考察了 XSLT 处理程序的工作原理.为了说明他的观点,他编写了专门的样式表把处理中的某些方面凸显出来.他特 ...

  2. Maven相关内容学习笔记一:基本配置和使用

    首先必须推荐的这本书<Maven实战> 许晓斌,机械工业出版社 Maven简介 其实使用Maven也有很久时间了,大部分都是别人建好了工程我使用一下,实际上并没有非常详细的使用经验,这次到 ...

  3. Self-Paced Training (1) - Introduction to Docker

    helloworld: wget -qo- https://get.docker.com/ | sh sudo docker run hello-world sudo usermod -aG dock ...

  4. sockaddr和sockaddr_in的区别(转载)

    原文链接:http://kenby.iteye.com/blog/1149001 struct sockaddr和struct sockaddr_in这两个结构体用来处理网络通信的地址. 在各种系统调 ...

  5. 【转】基于Android Fragment功能的例子

    原文网址:http://blog.csdn.net/eyu8874521/article/details/8252216 通过最近空闲时候对Fragment的学习,尝试着写了一个小Demo,将在开发的 ...

  6. 【转】angular Ajax请求

    1.http请求 基本的操作由 $http 服务提供.它的使用很简单,提供一些描述请求的参数,请求就出去了,然后返回一个扩充了 success 方法和 error 方法的 promise对象(下节介绍 ...

  7. SSL 通信原理及Tomcat SSL 配置

    SSL 通信原理及Tomcat SSL 双向配置 目录1 参考资料 .................................................................. ...

  8. POJ 2486-Apple Tree(树状背包)

    题意 n个节点的树,每个节点都有价值,求在树上最多走k步获得的最大价值(从1开始走,节点的价值只能获取一次) 分析: 开始以为是最基础的树形背包,但后来发现,不能只走子树,有可能还回到根节点,dp[i ...

  9. 卡尔曼滤波器【Kalman Filter For Dummies】

    搬砖到此: A Quick Insight     As I mentioned earlier, it's nearly impossible to grasp the full meaning o ...

  10. 用JSP做后台管理系统

    添加新闻 /**  * 获取从页面读取的数据  * @param request  * @return 单个新闻信息  * @throws UnsupportedEncodingException   ...