您的位置:首页 > 编程语言 > Java开发

Javase基础----List部分方法总结

2016-05-04 16:15 465 查看
ListArrayList(基本与List相同)

底层数据结构使用的是数组数据结构

数组结构,有角标,查询快,修改慢
LinkedList

(LinkedList特有方法)

底层数据结构使用的是链表数据结构

链表结构,查询慢,修改快
Vector

底层数据结构是数组数据结构
List特有方法:

ListIterator
add(index,element);

addAll(index,Collection);
add(index,element);

addAll(index,Collection);
addFirst();

addLast();

JDK1.6之后出现了替代方法

offerFirst();

offerLast();
  
remove(index);

clear();
remove(index);

removeRange(int fromIndex, int toIndex) 

移除列表中索引在 fromIndex(包括)和 toIndex(不包括)之间的所有元素。

clear();
removeFirst();

removeLast();

JDK1.6之后出现了替代方法

pollFirst();

pollLast();

获取元素,并且删除元素,如果集合中没有元素则返回null
已经基本被ArrayList取代

Vector是线程同步的

ArrayList线程不同步

这里要了解下Vector特有的枚举

(与迭代器类似):

Enumeration en = v.elements();

  

while(en.hasMoreElements());

{    System.out.println(en.nextElement());

}
在迭代时,不可以通过集合方法操作集合中的元素因为会发生ConcurrentModificationException异常

使用迭代器时,只有hasNext(),next()和remove()方法,没办法完成增删查改操作操作

这是就要使用到Iterator的子接口ListItetator

迭代方法:

正向:hasNext()

next()

逆向:hasPrevious()

previous()

增:add();

删:remove();

改:set();
set(index,elements);set(index,elements);   
get(index);

hashCode();

contains(Object o);

subList(from,to);

iterator();

listIterator();

size(); 

isEmpty(); 

subList(int fromIndex, int toIndex);

返回列表中指定的fromIndex(包括 )和 toIndex(不包括)之间的部分.

indexOf(Object o); 

正向第一次出现的位置

lastIndexOf(Object o);

逆向第一次出现的位置
get(index);

contains(Object o);

subList(from,to);

listIterator();

size(); 

isEmpty(); 

indexOf(Object o); 

lastIndexOf(Object o);
getFirst();

getLast();

JDK1.6之后出现了替代方法

peekFirst();

peekLast();

获取元素,但是不删除元素,如果集合中没有元素则返回null
  
 以上只是对自学视频内容及常用内容的总结,并不完全,想了解全部的方法,请查阅API文件
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: