1、ArrayList和LinkedList有何异同?
1.ArrayList是实现了基于动态数组的数据结构,LinkedList基于链表的数据结构。 (LinkedList
是双向链表,有next也有previous)
2.对于随机访问get和set,ArrayList觉得优于LinkedList,因为LinkedList要移动指针。
3.对于新增和删除操作add和remove,LinedList比较占优势,因为ArrayList要移动数据。
2、 遍历Set集合?
方法1:通过迭代器Iterator实现遍历
获取Iterator :Collection 接口的iterator()方法
Iterator的方法
boolean hasNext(): 判断是否存在另一个可访问的元素
Object next(): 返回要访问的下一个元素
方法2:增强型for循环
3、 遍历ArrayList集合
A.普通for循环
B.增强for循环
C.迭代
4、ArrayList和LinkedList的异同之处及各自的应用场合
1.ArrayList是实现了基于动态数组的数据结构,LinkedList基于链表的数据结构。 (LinkedList
是双向链表,有next也有previous)。
2.对于随机访问get和set,ArrayList觉得优于LinkedList,因为LinkedList要移动指针。
3.对于新增和删除操作add和remove,LinedList比较占优势,因为ArrayList要移动数据。