氟塑料離心泵www.buybeng.com

          jquery教程http://www.software8.co/wzjs/jquery/

          Collection的各種子類

          java集合框架支持三種主要類型的集合:規則集(Set),線性集(List)和隊列(Queue)。Set的實例用于存儲不重復的元素,List的實例用于存儲一個有元素構成的有序集合,Queue的實例用于存儲先進先出方式處理的對象。

          Set具體類是:散列類HashSet,鏈式散列類LinkedHashSet,樹形集TreeSet。HashSet的默認初始容量16而客座率為0.75.

          List 具體: ArrayList 和 LinkedList 具體區別就是 linkedList可以在任意位置插入刪除等操作,而arraylist的好處就是效率高

           

          談一下規則集和線性表的效率性能。

          import java.util.*;
          public class SetListPerformanceTest
          {
          public static void main(String[] args) 
          {
          Collection<Integer> set1 = new HashSet<Integer>();//HashSet
          System.out.println("Time"+getTestTime(set1,5000)+"milliseconds");

          Collection<Integer> set2 = new LinkedHashSet<Integer>();//LinkedHashSet
          System.out.println("Time"+getTestTime(set2,5000)+"milliseconds");

          Collection<Integer> set3 = new TreeSet<Integer>();//TreeSet
          System.out.println("Time"+getTestTime(set3,5000)+"milliseconds");

          Collection<Integer> set4 = new ArrayList<Integer>();//ArrayList
          System.out.println("Time"+getTestTime(set4,5000)+"milliseconds");

          Collection<Integer> set5 = new LinkedList<Integer>();//LinkedList
          System.out.println("Time"+getTestTime(set5,5000)+"milliseconds");

          }

          public static long getTestTime(Collection<Integer> c,int size){
          long startTime = System.currentTimeMillis();

          //add numbers 1,2,3,......size-1 to the array list
          List<Integer> list = new ArrayList<Integer>();
          for(int i=0;i<size;i++){
          list.add(i);
          }

          Collections.shuffle(list);//shuffle the array

          for(int element : list)
          c.add(element);

          Collections.shuffle(list);

          for(int element:list)
          c.remove(element);

          long endTime = System.currentTimeMillis();

          return endTime-startTime;
          }
          }

           

          通過上面的列子可以發現 規則集比線性表的效率高。但是還是要按照具體需求去選擇。

          ArrayList與vector 唯一不同的是訪問和修改向量的同步方法。使用ArrayList效率比vector高。

          stack是vector的子類、

           java教程http://www.software8.co/wzjs/java/1873.html

          隊列(Queue)和優先隊列(priorityQueue):隊列是一種先進先出的數據結構。元素被追加在隊尾,然后在隊頭被刪除。

          優先隊列中 元素被賦予優先級。最高優先級的元素先被刪除

          linkedList 實現了Deque接口,Deque接口又拓展了Queue接口。 因此可以用LinkedList接口來創建一個隊列。

           

          圖(Map):散列圖(HashMap),鏈式散列圖(LinkedHashMap)和樹形圖(TreeMap)

          HashMap中條目的順序是隨機的。TreeMap的條目是按照升序排列的。LinkedHashMap中的條目是按元素最后一次唄訪問的時間從早到晚排序的。
           

          import java.util.*;
          public class CountWordOfCurrent
          {
          public static void main(String[] args) 
          {
          //set text in a string
          String text = "Good moring. Have a good class."+"Have a good visit. Have fun!";
          //create a treemap to hold words as key and count as value
          TreeMap<String, Integer> map = new TreeMap<String, Integer>();

          String[] words = text.split("[ \n\t\r.,;!:?(){]");
          for(int i=0;i<words.length;i++){
          String key = words[i].toLowerCase();
          if(key.length()>0){
          if(map.get(key) == null){
          map.put(key,1);
          }
          else{
          int value = map.get(key).intValue();
          value++;
          map.put(key,value);
          }
          }
          }

          //create all entries into a set
          Set<Map.Entry<String,Integer>> entrySet = map.entrySet();
          //get key and value from each entry
          for(Map.Entry<String,Integer> entry : entrySet){
          System.out.println(entry.getValue()+"\t"+entry.getKey());
          }
          }
          }

          posted on 2012-12-18 09:41 你爸是李剛 閱讀(1508) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2012年12月>
          2526272829301
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          導航

          統計

          常用鏈接

          留言簿

          隨筆檔案

          文章檔案

          技術網站

          行業網站

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          站長網 氟塑料離心泵 注塑機 液晶廣告機
          主站蜘蛛池模板: 长宁县| 乳源| 新泰市| 应用必备| 太原市| 城固县| 武陟县| 滨州市| 四川省| 新昌县| 蓝田县| 庄河市| 东平县| 宁国市| 定陶县| 十堰市| 莱州市| 陆良县| 定兴县| 永靖县| 西丰县| 马公市| 礼泉县| 黄石市| 上蔡县| 平乡县| 米林县| 三明市| 榆中县| 嘉兴市| 抚州市| 当雄县| 通化县| 嘉鱼县| 洛隆县| 沿河| 濮阳市| 六枝特区| 衡阳市| 遂溪县| 澄城县|