集合类的区别

1.      Collection可以初始化为ArrayList或HashSet,例如:

private  Collection customers = new ArrayList< CustomerEO >();

或者:

private  Collection customers = new HashSet();

 

2.      Set可以初始化为HashSet,例如:

private  Set customers = new HashSet();

 

3.      List可以初始化为ArrayList,例如:

private  List customers = new ArrayList< CustomerEO >();

 

4.      Map可以初始化为HashMap,例如:

private  Map customers = new HashMap();

 

5.      集合类得选择

Collection类是Set和List的父类,在未确定使用Set还是List时可使用;

Set集合中的对象不能有重复,并且是无序的;

List集合中的对象可以有重复,并且可以有序排列;

Map集合是带有key和value值的集合;

你可能感兴趣的:(集合类的区别)