62,614
社区成员
发帖
与我相关
我的任务
分享
public class MySet<E> implements Set<E> {
List<E> list = new ArrayList<E>();
public boolean add(E o) {
if(list.contains(o))
return false;
list.add(o);
return true;
}
public boolean addAll(Collection<? extends E> c) {
boolean result = false;
for(E o : c)
result |= add(o);
return result;
}
public void clear() {
list.clear();
}
public boolean contains(Object o) {
return list.contains(o);
}
public boolean containsAll(Collection<?> c) {
for(Object o : c)
if(!contains(o))
return false;
return true;
}
public boolean isEmpty() {
return list.isEmpty();
}
public Iterator<E> iterator() {
return list.iterator();
}
public boolean remove(Object o) {
return list.remove(o);
}
public boolean removeAll(Collection<?> c) {
return list.removeAll(c);
}
public boolean retainAll(Collection<?> c) {
return list.retainAll(c);
}
public int size() {
return list.size();
}
public Object[] toArray() {
return list.toArray();
}
public <T> T[] toArray(T[] a) {
return list.toArray(a);
}
}