Java基础学习笔记之七(2)--List&Set
2013-01-26 10:43
501 查看
***List 接口
An ordered collection (also known as a sequence).Unlike sets, lists typically allow duplicate elements.
List接口是Collection的子接口,实现List接口的容器类中的元素
是有顺序的,而且是可以重复的。
List容器中的元素都对应一个整数型的序号,记载其在容器中的位置,
可以根据序号取容器中的元素。
ArrayList--底层是数组实现的List
LinkedList--底层是链表实现的List
常用方法:
1.Object get(int index)
Returns the element at the specified position in this list.
返回此列表中指定位置上的元素
2.Object set(int index,Object element)
Replaces the element at the specified position in this list
with the specified element
用指定的元素替代此列表中指定位置上的元素。
3.void add(E e)
Appends the specified element to the end of this list
将指定的元素追加到此列表的尾部。
4.void add(int index,E element)
Inserts the specified element at the specified position
in this list
将指定的元素插入此列表中的指定位置
5.Object remove(int index);
Removes the element at the specified position in this list.
移除此列表中指定位置上的元素。
6.int indexOf(Object o)
Returns the index of the first occurrence of the specified element
in this list
搜索指定元素在列表第一次出现的位置,如果没有返回-1
7.int lastIndexOf(Object o)
Returns the index of the last occurrence of the specified element
in this list.
返回指定的对象在列表中最后一次出现的位置索引。
***Set 接口
A collection that contains no duplicate elements.一个不包含重复元素的 collection。更正式地说,set 不包含
满足 e1.equals(e2) 的元素对 e1 和 e2,并且最多包含一个 null 元素。
主要实现类HashSet,可以用来过滤数据。Set方法参考API
***对比
选择哪种数据结构--读的效率和改的效率Array--读快,改慢(程序读的多时选择)
Linked--读慢,改快(程序改的多时选择)
Hash--两者之间
参考文章:
1.ArrayList 源码分析 /article/7665020.html
2.Java数组与内存控制 /article/8006001.html
3.数组在内存中的存放形式 http://www.linuxidc.com/Linux/2012-10/72887.htm
相关文章推荐
- python学习笔记-语法基础(dict&set)
- [原]java专业程序代写(qq:928900200),学习笔记之基础入门<正则表达式>(三十一)
- [原]java专业程序代写(qq:928900200),学习笔记之基础入门<SQL_Server_常用查询>(二十二)
- [原]java专业程序代写(qq:928900200),学习笔记之基础入门<Oracle_基础>(三十三)
- [原]java专业程序代写(qq:928900200),学习笔记之基础入门<javascript>(三十)
- Mybatis学习笔记:(二) java中的实体(对象、List、Set)关系怎样与数据库关联映射
- [原]java专业程序代写(qq:928900200),学习笔记之基础入门<Struts2_实战演练(中)>(三十九)
- [原]java专业程序代写(qq:928900200),学习笔记之基础入门<DOM解析>(三十二)
- Java基础学习笔记【07】Collection、List、Map
- Java基础学习笔记之七(1)--Collection接口&Collections集合工具类
- Java基础<十一>--->集合之List、Set
- 【Java学习笔记】基础知识学习12【Set接口的实现类】
- java基础教程学习笔记总结&nbsp;11-18节
- java学习笔记]java语言基础概述之内存的划分&堆和栈
- Java基础学习笔记(七)Set接口及其实现子类
- [原]java专业程序代写(qq:928900200),学习笔记之基础入门<SQL_Server_视图_函数_存储过程_触发器等>(二十三)
- java基础教程学习笔记总结&nbsp;7-10节
- [原]java专业程序代写(qq:928900200),学习笔记之基础入门<jsp>(二十六)
- Java基础:Collection—List&Set
- [原]java专业程序代写(qq:928900200),学习笔记之基础入门<servlet_文件下载>(二十七)