Java基础学习笔记之七(2)--List&Set

***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 源码分析    http://blog.csdn.net/xiazdong/article/details/8143332

2.Java数组与内存控制    http://blog.csdn.net/jzhf2012/article/details/8538793

3.数组在内存中的存放形式  http://www.linuxidc.com/Linux/2012-10/72887.htm

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值