激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

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

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

延伸 · 閱讀

精彩推薦
501
主站蜘蛛池模板: 欧美精品久久久久久久久久 | 毛片在哪看 | 九一国产精品 | 97人操| 亚洲综合一区二区三区 | 欧美成年私人网站 | 日本特级a一片免费观看 | 91高清完整版 | 午夜激情视频免费 | 97porn| 国产亚洲精品网站 | chinese xxxx hd pron8 tube| 久久精品视频免费观看 | 高清av在线| 91精品久久久久久久 | 黑人一级片视频 | 久久综合一区 | 婷婷一区二区三区四区 | 精品成人在线 | 91久久久久久久一区二区 | 精品黑人一区二区三区国语馆 | 欧美一级精品片在线看 | 成人男女啪啪免费观看网站四虎 | 黄色av.com | 国产精品久久久久久久娇妻 | 国产成人高清在线观看 | 性欧美xxxx免费岛国不卡电影 | 久久人人爽人人爽人人片av高请 | 一级片在线观看 | 国产亚洲精品久久久久久久软件 | 成人毛片免费看 | 免费久久精品 | 一级做a爱片毛片免费 | 久久精品亚洲精品国产欧美kt∨ | 秋霞a级毛片在线看 | 在线播放av片 | 午夜在线小视频 | 国产一区二精品区在线 | 精品一区二区三区免费 | 欧美日韩网站在线观看 | 中国毛片在线观看 |