java去重(1通过迭代器,2直接赋值)
2015-12-30 18:40
363 查看
1.List<Integer> list=new ArrayList<Integer>(); //有值
List<Integer> listTemp= new ArrayList<Integer>(); //临时的list
Iterator<Integer> it=list.iterator();//取得有值得list的迭代器
while(it.hasNext()){
int a = it.next();
if(listTemp.contains(a)){
it.remove();
}else{
listTemp.add(a);
}
}
2直接赋值
List<Integer> list=new ArrayList<Integer>(); //有值得
list List<Integer> tempList= new ArrayList<Integer>();
for(Integer i:list){
if(!tempList.contains(i)){
tempList.add(i);
}
}
List<Integer> listTemp= new ArrayList<Integer>(); //临时的list
Iterator<Integer> it=list.iterator();//取得有值得list的迭代器
while(it.hasNext()){
int a = it.next();
if(listTemp.contains(a)){
it.remove();
}else{
listTemp.add(a);
}
}
2直接赋值
List<Integer> list=new ArrayList<Integer>(); //有值得
list List<Integer> tempList= new ArrayList<Integer>();
for(Integer i:list){
if(!tempList.contains(i)){
tempList.add(i);
}
}
相关文章推荐
- 在源Eclipse上安装Myeclipse插件
- Java读写Excel文件示例
- Java中的自动装箱与拆箱
- (java)Implement strStr()
- Java 发送邮件
- 在Eclipse中安装Hibernate tools、Spring、Activiti插件
- Java 数组详解 - 用法、遍历、排序、实用API
- 【JavaWeb Structs2学习】 路径介绍(在JSP页面a标签怎么写1)
- 使用Java导出Excel案例详解
- Java list的用法排序及遍历
- 模仿QQ5.0界面侧滑
- JAVA中堆栈的定义及区别
- Eclipse中使用Gradle实现APK分包
- Java程序员之Spring(一) 入门
- java桌面显示出错,显示占半边,显绿色。
- Java中的几种引用类型:强引用、软引用、弱引用和虚引用
- Spring mvc 原理浅析
- java byte中存大于0x7E的十六进制数
- java基础篇
- error the @annotation pointcut expression is only supported at Java 5 compliance level or above