🐡
JavaのCollection Interface
Collection
interfaceというのがある。このインターフェイスに基づいて、いろんな種類のコレクションのサブインターフェースおよびサブタイプが実装されている。
Collection
interfaceから例えば、以下のサブインターフェイスが実装されている。
-
List
Interface -
Set
Interface
List
Interfaceを実装するクラスとしては、
ArrayList
LinkedList
ImmutableCollections$ListN
などがある。また、Set Interfaceを実装するクラスとしては以下がある。
ImmutableCollections$SetN
HashSet
Set
Interfaceをさらに拡張したインターフェイスというのもあって SortedSet
Interfaceがそれにあたる。
SortedSet
Interfaceを実装するクラスとしては、TreeSet
クラスがある。
以下のようにまとめることができる。
Collection<Integer> col1 = List.of(0,65,1);
Collection<Integer> col2 = Set.of(0,65,1);
System.out.println(col1.equals(col2)); // False
List.of
メソッドは、static factory methodと呼ばれるもので、変更不可能なcollectionを作成する。Set.of
メソッドも同様である。
Discussion