氟塑料離心泵www.buybeng.com

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

          Collection的各種子類(lèi)

          java集合框架支持三種主要類(lèi)型的集合:規(guī)則集(Set),線(xiàn)性集(List)和隊(duì)列(Queue)。Set的實(shí)例用于存儲(chǔ)不重復(fù)的元素,List的實(shí)例用于存儲(chǔ)一個(gè)有元素構(gòu)成的有序集合,Queue的實(shí)例用于存儲(chǔ)先進(jìn)先出方式處理的對(duì)象。

          Set具體類(lèi)是:散列類(lèi)HashSet,鏈?zhǔn)缴⒘蓄?lèi)LinkedHashSet,樹(shù)形集TreeSet。HashSet的默認(rèn)初始容量16而客座率為0.75.

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

           

          談一下規(guī)則集和線(xiàn)性表的效率性能。

          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;
          }
          }

           

          通過(guò)上面的列子可以發(fā)現(xiàn) 規(guī)則集比線(xiàn)性表的效率高。但是還是要按照具體需求去選擇。

          ArrayList與vector 唯一不同的是訪(fǎng)問(wèn)和修改向量的同步方法。使用ArrayList效率比vector高。

          stack是vector的子類(lèi)、

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

          隊(duì)列(Queue)和優(yōu)先隊(duì)列(priorityQueue):隊(duì)列是一種先進(jìn)先出的數(shù)據(jù)結(jié)構(gòu)。元素被追加在隊(duì)尾,然后在隊(duì)頭被刪除。

          優(yōu)先隊(duì)列中 元素被賦予優(yōu)先級(jí)。最高優(yōu)先級(jí)的元素先被刪除

          linkedList 實(shí)現(xiàn)了Deque接口,Deque接口又拓展了Queue接口。 因此可以用LinkedList接口來(lái)創(chuàng)建一個(gè)隊(duì)列。

           

          圖(Map):散列圖(HashMap),鏈?zhǔn)缴⒘袌D(LinkedHashMap)和樹(shù)形圖(TreeMap)

          HashMap中條目的順序是隨機(jī)的。TreeMap的條目是按照升序排列的。LinkedHashMap中的條目是按元素最后一次唄訪(fǎng)問(wèn)的時(shí)間從早到晚排序的。
           

          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 你爸是李剛 閱讀(1507) 評(píng)論(0)  編輯  收藏


          只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          <2012年12月>
          2526272829301
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿

          隨筆檔案

          文章檔案

          技術(shù)網(wǎng)站

          行業(yè)網(wǎng)站

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          站長(zhǎng)網(wǎng) 氟塑料離心泵 注塑機(jī) 液晶廣告機(jī)
          主站蜘蛛池模板: 景洪市| 且末县| 固镇县| 高清| 北辰区| 阿鲁科尔沁旗| 高安市| 海宁市| 盐津县| 达拉特旗| 佛山市| 平定县| 定南县| 贵阳市| 精河县| 贡山| 疏勒县| 手机| 鸡泽县| 河北省| 天水市| 日喀则市| 邢台市| 富顺县| 德州市| 黑山县| 景谷| 合山市| 长沙县| 额尔古纳市| 吉林市| 崇左市| 乌鲁木齐县| 阿坝| 盐亭县| 昌吉市| 五寨县| 茶陵县| 日土县| 佛教| 胶州市|