1. 程式人生 > >2.請介紹一下List和ArrayList的區別,ArrayList和HashSet區別

2.請介紹一下List和ArrayList的區別,ArrayList和HashSet區別

引用 equal ash arraylist 無序 lis 檢索 重復 lec

第一問:

  List是接口,ArrayList實現了List接口。

第二問:

  ArrayList實現了List接口,HashSet實現了Set接口,List和Set都是繼承Collection接口。

  ArrayList底層是動態數組,HashSet底層是哈希表。

  ArrayList存放的是對象的引用,HashSet存放之前檢索對象的HashCode,所以當存入對象時要重寫hashCode(),如果只是比較對象,只需要重寫equals()方法,

  ArrayList是有序可重復,HashSet是無序不可重復。

2.請介紹一下List和ArrayList的區別,ArrayList和HashSet區別