ConcurrentModificationException如何解决 list 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不可以在遍历ArrayList的时候还调用list的方法对其进行增删 集合的循环就是循环,不要在循环的同时去做增删操作另外要根据关键子判断是否同一个对象,优先考虑下用Map来存储将Map的key设置成你的关键字,值是你的对象,这样判断方便 Google this Exception,IF you find a lot of people talking it, just find how to fix it.If not, your program must be wrong. package cn.com.mytest.test;import java.util.ArrayList;import java.util.List;import com.mytest.po.student.Student;public class Test1 { public static void main(String[] args) { List<Student> personDisList = new ArrayList<Student>(); Student person1 = new Student(); person1.setId(1); person1.setName("test1"); person1.setClassName("sfs"); person1.setAge(12); Student person2 = new Student(); person2.setId(2); person2.setName("test2"); person2.setClassName("231s"); person2.setAge(11); personDisList.add(person1); personDisList.add(person2); List<Student> personList = new ArrayList<Student>(); for (int i=0; i<personDisList.size(); i++){ Student person=new Student(); person.setId(personDisList.get(i).getId()); if(personList.size()!=0){ boolean bn=false; for (int j=0;j<personList.size();j++) { if(personDisList.get(i).getId()!=personList.get(j).getId());{ personList.add(personDisList.get(i)); break; } } }else{ personList.add(person); } System.out.println(personList.size()); } } }楼主看看这是不是你要的代码; ClassPath很久的疑问 Jtabel的数据请教 小程序未初始化 麻烦写出对象"生成器"(Generator)的实现代码 请各位指点下以下程序的输出问题。。 怎么得到PreparedStatement对象executeQuery()函数所返回的结果集行数?? 如何在两个文件之间共享同一个bean的实例? 网页跟applet互传数据问题 各位大虾,来给我的project topic提提看法 怎样为SSLContext创建一个实例? Java如何调用windows资源管理器的右键菜单 这样限制了text的输入,就不能输入string型的数据?
If not, your program must be wrong.
import java.util.List;import com.mytest.po.student.Student;public class Test1 {
public static void main(String[] args) {
List<Student> personDisList = new ArrayList<Student>();
Student person1 = new Student();
person1.setId(1);
person1.setName("test1");
person1.setClassName("sfs");
person1.setAge(12);
Student person2 = new Student();
person2.setId(2);
person2.setName("test2");
person2.setClassName("231s");
person2.setAge(11);
personDisList.add(person1);
personDisList.add(person2); List<Student> personList = new ArrayList<Student>();
for (int i=0; i<personDisList.size(); i++){
Student person=new Student();
person.setId(personDisList.get(i).getId());
if(personList.size()!=0){
boolean bn=false;
for (int j=0;j<personList.size();j++) {
if(personDisList.get(i).getId()!=personList.get(j).getId());{
personList.add(personDisList.get(i));
break;
}
}
}else{
personList.add(person);
}
System.out.println(personList.size());
}
}
}楼主看看这是不是你要的代码;