Chinaunix首页 | 论坛 | 博客
  • 博客访问: 152420
  • 博文数量: 47
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 405
  • 用 户 组: 普通用户
  • 注册时间: 2014-11-23 14:38
文章分类

全部博文(47)

文章存档

2017年(7)

2016年(4)

2015年(19)

2014年(17)

我的朋友

分类: Java

2015-08-01 20:12:05

List:interface  继承自Collection
API中是这么介绍的: An ordered collection (also known as a sequence).  The user of this interface has precise control over where in the list each element is inserted.  The user can access elements by their integer index (position in the list), and search for elements in the list.


也就是说list有点像升级版的数组,可以依靠索引取值和存值,也能够实现在特定位置插入。
相对于Collection新声明的方法:
                 E get(int index);               
                 E set(int index, E element);       //替换指定位置的元素
                 void add(int index, E element);      //在指定位置插入元素
                E remove(int index);
                 int indexOf(Object o);
两种类型:
1.ArrayList     长于随意访问,但插入和移除元素时相对慢
2.LinkedArrayList  插入和删除操作时开销小

需要注意的是:在list中部做包含,删除等需要对元素比对的操作时,需要依赖于equals()方法,所以会得到什么结果依赖于对象的equals()方法

阅读(1039) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~