一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - java 中RandomAccess接口源碼分析

java 中RandomAccess接口源碼分析

2020-11-01 23:05songwenlong Java教程

這篇文章主要介紹了java 中RandomAccess接口源碼分析的相關資料,需要的朋友可以參考下

javaRandomAccess接口源碼分析

RandomAccess是一個接口,位于java.util包中。

這個接口的作用注釋寫的很清楚了:

 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
 * Marker interface used by <tt>List</tt> implementations to indicate that
 * they support fast (generally constant time) random access. The primary
 * purpose of this interface is to allow generic algorithms to alter their
 * behavior to provide good performance when applied to either random or
 * sequential access lists.
 * List實現所使用的標記接口,用來表明實現了這些接口的list支持快速(通常是常數時間)隨機訪問。
 * 這個接口的主要目的是允許一般的算法更改它們的行為,以便在隨機或者順序存取列表時能提供更好的性能。
 * <p>The best algorithms for manipulating random access lists (such as
 * <tt>ArrayList</tt>) can produce quadratic behavior when applied to
 * sequential access lists (such as <tt>LinkedList</tt>). Generic list
 * algorithms are encouraged to check whether the given list is an
 * <tt>instanceof</tt> this interface before applying an algorithm that would
 * provide poor performance if it were applied to a sequential access list,
 * and to alter their behavior if necessary to guarantee acceptable
 * performance.
 * 操作隨機訪問列表(如ArrayList)的最佳算法在應用于順序存取列表時,有可能產生二次項行為。
 * 泛型算法列表鼓勵在將某個算法應用于順序存取列表可能導致差的性能之前,先檢查給定的列表是否是這個接口的一個實例,
 * 并在需要時去改變這些算法的行為以保證性能。
 * <p>It is recognized that the distinction between random and sequential
 * access is often fuzzy. For example, some <tt>List</tt> implementations
 * provide asymptotically linear access times if they get huge, but constant
 * access times in practice. Such a <tt>List</tt> implementation
 * should generally implement this interface. As a rule of thumb, a
 * <tt>List</tt> implementation should implement this interface if,
 * for typical instances of the class, this loop:
 
 * 隨機訪問和順序存取之間的界限通常是模糊的。例如,一些List實現在變得很大時會導致漸進的非線性訪問時間,但實際上是常量訪問時間。
 * 這樣的List實現通常都應該實現該接口。
 * 一般來說,某個List實現如果(對某些典型的類的實例來說)滿足下面的條件,就應該實現這個接口:循環
 * <pre>
 *   for (int i=0, n=list.size(); i &lt; n; i++)
 *     list.get(i);
 * </pre>
 * runs faster than this loop:
 * 比下面的循環運行速度快。
 * <pre>
 *   for (Iterator i=list.iterator(); i.hasNext(); )
 *     i.next();
 * </pre>
 *
 * <p>This interface is a member of the
 * <a href="{@docRoot}/../technotes/guides/collections/index.html" rel="external nofollow" >
 * Java Collections Framework</a>.
 * 這個接口是Java集合框架的一員。
 * @since 1.4
 */
public interface RandomAccess {
}

 RandomAccess是一個空接口,而空接口的作用一般是起到一個標識的作用。

通俗點講,就是判斷一個list是否實現了RandomAcess接口,如果實現了,采用下面所示的簡單的for循環進行訪問速度比較快:

?
1
2
for (int i=0, n=list.size(); i &lt; n; i++)
   list.get(i);

如果未實現RandomAcess接口,則采用下面的iterator循環訪問速度比較快。

?
1
2
for (Iterator i=list.iterator(); i.hasNext(); )
   i.next();

判斷使用instanceof,即

?
1
if (list instanceof RandomAccess)

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

原文鏈接:http://www.cnblogs.com/songwenlong/p/6901669.html

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 青青青国产成人久久111网站 | 国产欧美日韩不卡一区二区三区 | 久久久免费热线精品频 | 91porn最新网址| 免费高清视频免费观看 | 国产一区私人高清影院 | 毛片啪啪视频 | 婷婷精品 | 青青草一区二区免费精品 | 奇米视频7777 | 性一交一无一伦一精一品 | 国产成人精品一区二区仙踪林 | 久久婷婷五月综合色精品首页 | 高h喷水荡肉爽文np肉色文 | 午夜神器18以下不能进免费 | 欧美综合国产精品日韩一 | 欧美美女被爆操 | 91次元成年破解版 | 嗯啊在线观看免费影院 | 亚洲区视频在线观看 | a毛片在线免费观看 | 77成人影院| 成人福利在线观看 | 成年人视频在线免费观看 | 久久青青草原综合伊人 | 亚洲精品国产精麻豆久久99 | 欧美国产精品 | 高清视频在线播放ww | 无人在线高清免费看 | 欧美一级片在线看 | 恩不要好大好硬好爽3p | 青山葵在线 | 国产成人精品高清不卡在线 | 亚洲福利二区 | 18xxxx中国 | 男人的天堂久久精品激情 | 国产一及毛片 | 国内精品一区视频在线播放 | 91sao在线看片水片 | 香蕉视频久久 | 69人成网站色www |