<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Vincent Jia 博客

    to be a better man, to be a bad man.

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      29 隨筆 :: 3 文章 :: 0 評論 :: 0 Trackbacks

    2012年6月29日 #

    2016年,收獲了什么,失去了什么。 
    博客沒有寫作。
    國家大事件幾多。
    posted @ 2017-12-04 16:53 iLinux 閱讀(221) | 評論 (0)編輯 收藏

    The Collections Framework







    The collections framework is a unified architecture for representing and manipulating collections, allowing them to be manipulated independently of the details of their representation. It reduces programming effort while increasing performance. It allows for interoperability among unrelated APIs, reduces effort in designing and learning new APIs, and fosters software reuse. The framework is based on fourteen collection interfaces. It includes implementations of these interfaces, and algorithms to manipulate them.
    Overview
    • Overview - An overview of the Collections framework.
    API Specification
    • API Reference - An annotated outline of the classes and interfaces comprising the collections framework, with links into the JavaDoc.
    Tutorials and Programmer's Guides
    • Tutorial - A tutorial introduction to the collections framework with plenty of programming examples.
    API EnhancementsMore Information
    • Design FAQ- Answers to frequently asked questions concerning the design of the collections framework.

    From: http://docs.oracle.com/javase/6/docs/technotes/guides/collections/index.html
    posted @ 2012-07-06 16:15 iLinux 閱讀(279) | 評論 (0)編輯 收藏

    API Enhancements

    posted @ 2012-07-06 16:14 iLinux 閱讀(284) | 評論 (0)編輯 收藏

    LinkedHashSet是JDK 1.4中引入的新的集合類(LinkedHashMap也是同期引入)。 LinkedHashSet,顧名思義,就是在Hash的實現上添加了Linked的支持。對于LinkedHashSet,在每個節點上通過一個鏈表串聯起來,這樣,就可以保證確定的順序。對于希望有常量復雜度的高效存取性能要求、同時又要求排序的情況下,可以直接使用LinkedHashSet。

    它實現了Set接口。存入Set的每個元素必須是唯一的,因為Set不保存重復元素。但是Set接口不保證維護元素的次序(那里面的元素每次順序如何確定?TODO)。Set與Collection有完全一樣的接口Iterable,同時Set繼承了Collection。

    LinkedHashSet具有HashSet的查詢速度,且內部使用鏈表維護元素的順序(插入的順序),于是在使用迭代器便利Set時,結果會按元素插入的次序顯示。

    需求如: 含多個(有重復)元素ArrayList,去除重復。

    1, 可以使用如下略顯冗余的代碼:
     1 public static List removeDuplicateWithOrder(List list) {
     2         Set set = new HashSet();
     3         List newList = new ArrayList();
     4         for (Iterator iter = list.iterator(); iter.hasNext();) {
     5             Object element = iter.next();
     6             if (set.add(element))
     7                 newList.add(element);
     8         }
     9         return newList;
    10     }
    此方法有濫用set之嫌。

    2, 我們也可以使用本文章中提及的LinkedHashSet:
    return new ArrayList<T>(new LinkedHashSet<T>(list));
    此方法,既利用set去除了重復,又使用linked保持住了原順序。

    3, 貌似apache commons lang中有專門去重復的集合工具。

    這兒的鏈表操作是常量級的,這也是LinkedHashSet/LinkedHashMap比TreeSet/TreeMap性能更高的原因。當然,LinkedHashSet不是thread-safe的,在多線程環境下,需要進行同步包裝:
    Collections.synchronizedCollection(Collection);
    or:
    Collections.synchronizedSet(Set);
    在使用LinkedHashSet的iterator()方法遍歷元素時,如果其他線程有讀取操作,也要進行同步,否則,就會拋出同其它fail-fast一樣的由于刪除或增加操作而引起的CurrentModificationException。


    如上兩種方法的效率比較,設為TODO,
    1, 利用set.add(element)方法,本質是利用其contains()方法判斷,而contains()的本質就是遍歷。
    JDK doc中寫道:
    More formally, adds the specified element e to this set if the set contains no element e2 such that (e==null ? e2==null : e.equals(e2)). If this set already contains the element, the call leaves the set unchanged and returns false. In combination with the restriction on constructors, this ensures that sets never contain duplicate elements.
    2, 測試數據,可以使用數據量:1W,5W,10W,100W。

    posted @ 2012-07-06 11:54 iLinux 閱讀(6227) | 評論 (0)編輯 收藏

    在當前的系統中,大量使用了非泛型模式的Collection、List、Map、HashMap、HashTable。
    其關系、區別在于。
    posted @ 2012-06-29 17:50 iLinux 閱讀(267) | 評論 (0)編輯 收藏

    主站蜘蛛池模板: 91精品免费观看| 暖暖在线视频免费视频| 在线观看免费成人| 亚洲中文无码线在线观看| 久久精品免费一区二区| 亚洲最大免费视频网| 免费三级毛片电影片| 亚洲最大视频网站| 91麻豆最新在线人成免费观看| 亚洲欧洲自拍拍偷综合| 成人奭片免费观看| 亚洲av永久无码精品秋霞电影秋 | 久9这里精品免费视频| 亚洲精品自产拍在线观看动漫| 91在线手机精品免费观看| 亚洲国产成人va在线观看网址| 在线观看视频免费完整版| 亚洲精品GV天堂无码男同| 亚洲v国产v天堂a无码久久| WWW免费视频在线观看播放| 日产亚洲一区二区三区| 成人爽A毛片免费看| 免费国产在线精品一区 | 久久精品a一国产成人免费网站| 亚洲a∨无码男人的天堂| 国产日产成人免费视频在线观看| 特级毛片全部免费播放| 亚洲精品成人无限看| 在线永久看片免费的视频| 国产亚洲综合精品一区二区三区| 中文字幕第一页亚洲| 1000部啪啪未满十八勿入免费| 亚洲日韩国产欧美一区二区三区| 亚洲人成网站观看在线播放 | www.999精品视频观看免费| 精品久久亚洲一级α| 亚洲AV无码专区电影在线观看| 18禁成年无码免费网站无遮挡| GOGOGO免费观看国语| 亚洲天天在线日亚洲洲精| 国产精品高清全国免费观看|