K
Karsten Wutzke
Hello!
I have the following method overriding Collection.addAll:
@Override
public boolean addAll(int index, Collection<? extends E> cln)
{
if ( containsAll(cln) )
{
return false;
}
//build list without dupes (always)
ArrayList<E> al = new ArrayList<E>(cln.size());
Iterator<? extends E> itr = cln.iterator();
while ( itr.hasNext() )
{
E elem = itr.next();
if ( !contains(elem) )
{
al.add(elem);
}
}
cln = al;
//allows dupes and nulls
return super.addAll(index, cln);
}
Is there any faster way without overriding other methods?
Karsten
I have the following method overriding Collection.addAll:
@Override
public boolean addAll(int index, Collection<? extends E> cln)
{
if ( containsAll(cln) )
{
return false;
}
//build list without dupes (always)
ArrayList<E> al = new ArrayList<E>(cln.size());
Iterator<? extends E> itr = cln.iterator();
while ( itr.hasNext() )
{
E elem = itr.next();
if ( !contains(elem) )
{
al.add(elem);
}
}
cln = al;
//allows dupes and nulls
return super.addAll(index, cln);
}
Is there any faster way without overriding other methods?
Karsten