ArrayList Set Map

mac2022-06-30  20

Map->HashMap(键和值hash相关)

线性表List->ArrayList(快速索引)

 

Map<Integer, Integer> map = new HashMap<>(); for (int i = 0; i < nums.length; i++) { map.put(nums[i], i); }

 

put/ get/ containsKey

 

 

 

1.ArrayList类提供了List ADT的一种可增长数组的实现。使用ArrayList的优点在于,对get和set的调用花费常数时间。其缺点是新项的插入和现有项的删除代价昂贵,除非变动是在ArrayList的末端是在ArrayList的末端运行。

2.LinkedList类则提供了List ADT的双链表实现。使用LinkedList的优点在于,新项的插入和现有项的删除均开销很小。

 

 

https://blog.csdn.net/speedme/article/details/8199418

 

https://blog.csdn.net/vict_wang/article/details/81590545

 

ArrayList和Set的Contains效率

Arraylist -> indexOf

Set -> Hashtable

https://blog.csdn.net/fenglibing/article/details/9021201

转载于:https://www.cnblogs.com/ppCola/p/11301209.html

最新回复(0)