public static ArrayList singleElements(ArrayList al)
{
ArrayList newAl = new ArrayList();
for(Iterator it = al.iterator();it.hasNext();)
{
Object obj = it.next();
while(!newAl.contains(obj))
{
newAl.add(obj);
}
}
return newAl;
}
为什么改成这样不行,就是不需要用Object,会报错找不到这个元素
public static ArrayList singleElements(ArrayList al)
{
ArrayList newAl = new ArrayList();
for(Iterator it = al.iterator();it.hasNext();)
{
while(!newAl.contains(it.next())
{
newAl.add(it.next());
}
}
return newAl;
}
|
|