一天一个类,一点也不累 之 LinkedList
2015-04-23 19:36
302 查看
我们的口号是,一天一个类,一点也不累 。。
今天要讲的是---LinkedList
首先,还是看看他的组织结构
相比上两次介绍的两个类,他的实现接口多了一个Queue & Deque(一个是队列一个是双端队列)
既然这个也实现了List,同样具有List的一些性质,不知大家是否还记得List中的对象容许为NULL.
在API的官网上面明确说了一句:【[b]Note that this implementation is not synchronized.】 也就是说LinkedList也是非线程安全的。
[/b]
和ArrayList一样,库中存在线程安全的实现方法:
List list = Collections.synchronizedList(new LinkedList(...));
所以在非线程安全的容器里面会有一个用来记录该对象改变次数的计数器modCount.
【首先声明一下,这个LinkedList里面维持这两个对象,一个是first,一个是last,他们的数据类型是Node的内部类。
1、构造方法:
Constructs an empty list.
Constructs a list containing the elements of the specified collection, in the order they are returned by the collection's iterator.
2、首先特别解释一下,transient,这样的对象在行进序列话的时候, 是不被需序列化的,是临时的。
因为在读源码的时候经常会出现这个关键字。
3、因为这个是链表,所以提供了一些关于链表的操作。
e.g. getFirst() getLast()。。。。。。
4、值得注意的是从1.6开始,新增了一项称道的方法(虽然自己可以方便实现),这就是能够生成倒序的迭代器。
这样以来就满足了在特定场合的需要。
哇喔,这个类要说的好少啊!~~~
不再说的多少,而在多思多练。
中国有句谚语:
不闻不若闻之,闻之不若见之,见之不若知之,知之不若行之。
今天要讲的是---LinkedList
首先,还是看看他的组织结构
Class LinkedList<E> java.lang.Object java.util.AbstractCollection<E> java.util.AbstractList<E> java.util.AbstractSequentialList<E> java.util.LinkedList<E> Type Parameters: E - the type of elements held in this collection All Implemented Interfaces: Serializable, Cloneable, Iterable<E>, Collection<E>, Deque<E>, List<E>, Queue<E> public class LinkedList<E> extends AbstractSequentialList<E> implements List<E>, Deque<E>, Cloneable, Serializable
相比上两次介绍的两个类,他的实现接口多了一个Queue & Deque(一个是队列一个是双端队列)
既然这个也实现了List,同样具有List的一些性质,不知大家是否还记得List中的对象容许为NULL.
在API的官网上面明确说了一句:【[b]Note that this implementation is not synchronized.】 也就是说LinkedList也是非线程安全的。
[/b]
和ArrayList一样,库中存在线程安全的实现方法:
List list = Collections.synchronizedList(new LinkedList(...));
所以在非线程安全的容器里面会有一个用来记录该对象改变次数的计数器modCount.
【首先声明一下,这个LinkedList里面维持这两个对象,一个是first,一个是last,他们的数据类型是Node的内部类。
private static class Node<E> { E item; Node<E> next; Node<E> prev; Node(Node<E> prev, E element, Node<E> next) { this.item = element; this.next = next; this.prev = prev; } }
1、构造方法:
[b] LinkedList()[/b]
Constructs an empty list.
[b] LinkedList(Collection<? extends E> c)[/b]
Constructs a list containing the elements of the specified collection, in the order they are returned by the collection's iterator.
2、首先特别解释一下,transient,这样的对象在行进序列话的时候, 是不被需序列化的,是临时的。
因为在读源码的时候经常会出现这个关键字。
3、因为这个是链表,所以提供了一些关于链表的操作。
e.g. getFirst() getLast()。。。。。。
4、值得注意的是从1.6开始,新增了一项称道的方法(虽然自己可以方便实现),这就是能够生成倒序的迭代器。
/** * Adapter to provide descending iterators via ListItr.previous */ private class DescendingIterator implements Iterator<E> { private final ListItr itr = new ListItr(size()); public boolean hasNext() { return itr.hasPrevious(); } public E next() { return itr.previous(); } public void remove() { itr.remove(); } }
这样以来就满足了在特定场合的需要。
哇喔,这个类要说的好少啊!~~~
不再说的多少,而在多思多练。
中国有句谚语:
不闻不若闻之,闻之不若见之,见之不若知之,知之不若行之。
相关文章推荐
- 一天一个类,一点也不累 之 Vector
- 一天一个类,一点也不累之HashSet
- 一天一个类,一点也不累之TreeSet
- 一天一个类,一点也不累 之 Set接口
- [一天一点java]一个简单的计数器
- [一天一项目]逆转字符串——输入一个字符串,将其逆转并输出。
- 作为练习,是帮别人免费做的一个。做东西不能没有收获,虽然是小东西,且用vb但是尽量想些正规一点
- 【一天一个shell命令】文本操作系列-comm
- 在2006年的最后一天,我做出了一个决定
- 一天一点xib:5当xib遇到auto layout
- Help!编了一个计算器的程序,却出了一点问题。
- 一个菜鸟的一点思考
- js判断一点是否在一个三角形内
- 第二夜 半脸人 异闻录——每晚一个离奇故事 敬请期待,一天,一个离奇故事!如果您喜欢,请在评论里发表您的高见,支持,每天一个新故事!
- WCF 一步一步从入门到精通(一)建立一个简单入门的例子(适合一点不会的朋友阅读)
- 勤奋吧,一天一点,努力提高基本技能。
- 一天同时输入的所有入库单所对应的采购单的一个编号的产品的入库汇总
- 一天一个设计模式---命令模式
- 对上一篇文章: java求助的一点改进,但是还是存在一个很严重的错误,继续求助????
- linux一天一个脚印:进程的管理