1。问题。
我定义了一个linkedList,在使用linkedList的add(object)方法中。我们把对象写入数组列表
结果用
Stats cc;
//System.out.println(con.size()+"---------------------");
int count = con.size();
try{
if(con!=null)
{
for(int i=0;i<count;i++)
{
cc = (Stats)con.get(i);
cc.close();
//con.remove(i);
//System.out.println("love");
}
}
}catch(Exception e){
System.out.println(e.getMessage().toString());
}
结果发现总有几个连接关不到,结果发现原来是con.remove(i)的原因,
原因在于,当con.remove(i)执行后,数组对象的个数减了1,
如果总数为4,那么con.remove(i)后,数组对象只有3个啦,如果执行con.remove(i),当i=3时就会出错。
原因在于,这种列表,他不是索引不变的,也就是说,他删除一个,索引会自动前移。
我定义了一个linkedList,在使用linkedList的add(object)方法中。我们把对象写入数组列表
结果用
Stats cc;
//System.out.println(con.size()+"---------------------");
int count = con.size();
try{
if(con!=null)
{
for(int i=0;i<count;i++)
{
cc = (Stats)con.get(i);
cc.close();
//con.remove(i);
//System.out.println("love");
}
}
}catch(Exception e){
System.out.println(e.getMessage().toString());
}
结果发现总有几个连接关不到,结果发现原来是con.remove(i)的原因,
原因在于,当con.remove(i)执行后,数组对象的个数减了1,
如果总数为4,那么con.remove(i)后,数组对象只有3个啦,如果执行con.remove(i),当i=3时就会出错。
原因在于,这种列表,他不是索引不变的,也就是说,他删除一个,索引会自动前移。