13行目: 13行目:


===例===
===例===
  Set<String>colors = new HashSet<>();
  Set<String> colors = new HashSet<>();
  colors.add("red");
  colors.add("red");
  colors.add("yellow");
  colors.add("yellow");

2019年6月20日 (木) 20:53時点における版

java.util.HashSet [1]

私はハッシュ表を利用してデータを扱います。重複データは無視します。

メソッド

  • isEmpty - このセットに要素が存在するか真偽します
  • contains - 指定された要素がセットに含まれているか真偽します
  • size - セット内の要素数を知らせます
  • add - その要素をセットに追加します
  • clear - すべての要素をセットから削除します
  • remove - 要素をセットから削除します

Set<String> colors = new HashSet<>();
colors.add("red");
colors.add("yellow");
colors.add("blue");
colors.add("blue");
System.out.println(colors.size());