2020 |
07,27 |
import java.util.*;
/*
HashSetクラスについて
HashSetなのですがArrayList同様重複のデータを扱うものですが、
重複を許さない点とデータを保持する順番が定まらない点が異なります
*/
public class MyApp{
public static void main(String[] args){
//HashSet
//HashSet<Integer> sales = new HashSet<>();
Set<Integer> sales = new HashSet<>();
salse.add(10);
salse.add(20);
salse.add(30);
salse.add(10);
//重複した値を許さないので3個になるはずです。
System.out.println(sales.size());//3
for(Integer sale : sales){
System.out.println(sale);
}
sales.remove(30);
for(Integer sale : sales){
System.out.println(sale);
}
}
}
PR
Post your Comment