熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

Java.until.Map,Set,List的資料整理

2022-06-13   來源: JSP教程 

  CollecitonFramework(JSDK )一般用途Class作方式
  
 

  Collection Framework(JSDK )一般用途Class特色與食用范圍比較
  

  Collections => Collection是所有List跟Set的始祖List必須以特定次序來持有對象Set無法擁有重復元素
  
  ArrayList => 用Array實做的List允許快速隨機存取相較於LinkedList 不適合拿來進行元素安插和移除動作
  LinkedList => 提供最佳循序存取適合安插和移除元素隨機存取動作比起ArrayList緩慢
  
  HashSet => 是一種collection但是只存放唯一值是把搜尋時間看的很重要的set用hash方式實作的set故access time complexity = O()
  
  TreeSet => 同上但是存入的元素都會經過排列所以速度比HashSet 慢一點
  
  LinkedHashSet =>
  Performance is likely to be just slightly below that of HashSet due to the added expense of maintaining the linked list with one exception: Iteration over a LinkedHashSet requires time proportional to the size of the set regardless of its capacity Iteration over a HashSet is likely to be more expensive requiring time proportional to its capacity
  
  BitSet => 能夠高效率的儲存大量 [ / ] (開/關) 資料
  
  HashMap => 用來取代HashTable儲存 (key/value) pairs
  TreeMap => 儲存 (key/value) pairs會自動根據Key值排序
  
  LinkedHashMap =>
  Performance is likely to be just slightly below that of HashMap due to the added expense of maintaining the linked list with one exception: Iteration over the collectionviews of a LinkedHashMap requires time proportional to the size of the map regardless of its capacity Iteration over a HashMap is likely to be more expensive requiring time proportional to its capacity
  
  IdentityHashMap =>
  This has better locality for large tables than does using separate arrays) For many JRE implementations and operation mixes this class will yield better performance than HashMap (which uses chaining rather than linearprobing
  
  WeakHashMap => 這個map中由於每個Value僅存在一個實體因而節省了儲存空間一但程序需要某個Value便在map中搜尋既有的對象並使用找到的那個對象(而非重新再造一個)由於這是一種節省儲存空間的技巧所以能夠方便的讓GC自動清理Key和Value一但Key不在被使用便會觸發清理動作
  
  容器簡介
  容器的分類
  Collection一組各自獨立的元素即其內的每個位置僅持有一個元素
  )List以元素安插的次序來放置元素不會重新排列
  )Set不接愛重復元素它會使用自己內部的一個排列機制
  Map一群成對的keyvalue對象即所持有的是keyvalue pairs
  Map中不能有重復的key它擁有自己的內部排列機制
  容器中的元素類型都為Object從容器取得元素時必須把它轉換成原來的類型
  

From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19793.html
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.