Collectionインターフェースの詳細
Collectionインターフェース
Collectionインターフェースは集合類の親インターフェースとして、Collectioはjava.utilパッケージの下にあり、Collectioは多くのセット操作の方法を定義しています。今日はソースコードの確認を通じてCollectionインターフェースを認識したいです。以下は直接ソースコードの分析に入ります。
Collectionインタフェースのソースコード
CollectionインターフェースはIterableインターフェースを継承することが分かる。
Collectionインターフェース方法のまとめと詳細解
Collectionインターフェースは集合類の親インターフェースとして、Collectioはjava.utilパッケージの下にあり、Collectioは多くのセット操作の方法を定義しています。今日はソースコードの確認を通じてCollectionインターフェースを認識したいです。以下は直接ソースコードの分析に入ります。
Collectionインタフェースのソースコード
CollectionインターフェースはIterableインターフェースを継承することが分かる。
Collectionインターフェース方法のまとめと詳細解
package java.util;
import java.util.function.Predicate;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
public interface Collection extends Iterable {
/**
* @return ( )
*/
int size();
/**
* @return , true
*/
boolean isEmpty();
/**
* , true
*
* @param o
*/
boolean contains(Object o);
/**
* @return
*/
Iterator iterator();
/**
* @return
*/
Object[] toArray();
/**
* @return
*/
T[] toArray(T[] a);
/**
* @return , true
*/
boolean add(E e);
/**
* @return , true
*/
boolean remove(Object o);
/**
* @return C, true
*/
boolean containsAll(Collection> c);
/**
* @return C , true
*/
boolean addAll(Collection extends E> c);
/**
* @return C, true
*/
boolean removeAll(Collection> c);
/**
* @return , true
* @since 1.8
*/
default boolean removeIf(Predicate super E> filter) {
Objects.requireNonNull(filter);
boolean removed = false;
final Iterator each = iterator();
while (each.hasNext()) {
if (filter.test(each.next())) {
each.remove();
removed = true;
}
}
return removed;
}
/**
* @return C
*/
boolean retainAll(Collection> c);
/**
*
*/
void clear();
/**
* @return O
*/
boolean equals(Object o);
/**
* @return 。
*/
int hashCode();
/**
*
* @return a {@code Spliterator} over the elements in this collection
* @since 1.8
*/
@Override
default Spliterator spliterator() {
return Spliterators.spliterator(this, 0);
}
/**
* @return a sequential {@code Stream} over the elements in this collection
* @since 1.8
*/
default Stream stream() {
return StreamSupport.stream(spliterator(), false);
}
/**
* @return a possibly parallel {@code Stream} over the elements in this
* collection
* @since 1.8
*/
default Stream parallelStream() {
return StreamSupport.stream(spliterator(), true);
}
}