码迷,mamicode.com
首页 > 其他好文 > 详细

JDK 源码解读之 ArrayList

时间:2017-08-09 19:09:46      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:元素   flow   near   pen   ide   over   list   ext   splay   

技术分享
public class ArrayList<E> extends AbstractList<E>
        implements List<E>, RandomAccess, Cloneable, java.io.Serializable
View Code

  文档中提到:size isEmpty get set iterator listIterator 操作,是( run in constant time), add操作是(run in amortized constant time),而 其他的操作是 (run in linear time).

  Constant time means the operation doesn‘t depend on the length of the input. Linear time means the operation grows linearly with the change in the length of the input.

  就想比较 两个(4bytes int a ,b)的大小是 constant time,并不会因为 a,b的大小而不同。用大O表示法就是:O(1)。而 找出一个数组中 最大的 值,就是Linear time,因为时间随着 数组中元素的增加而增加。用大O表示法就是:O(n)。

  什么是amortized constant time呢?

  StackOverFlow上是这么说的:

    If you do an operation say a million times, you don‘t really care about the worst-case or the best-case of that operation - what you care about is how much time is taken in total when you repeat the operation a million times.

   Essentially amortised time means "average time taken per operation, if you do many operations". Amortised time doesn‘t have to be constant; you can have linear and logarithmic amortised time or whatever else.

  

JDK 源码解读之 ArrayList

标签:元素   flow   near   pen   ide   over   list   ext   splay   

原文地址:http://www.cnblogs.com/goodearth/p/7327058.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!