飛翔的起點(diǎn)

          從這里出發(fā)

          導(dǎo)航

          <2009年10月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          統(tǒng)計(jì)

          常用鏈接

          留言簿(5)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          2009年10月18日 #

          Queue

          public class QuenDemo {
            public static void main(String[] args){
             //public class Queue extends Collection
             Queue<Integer> queue=new LinkedList<Integer>();
             Random  rand = new Random(47);
             for(int i=0;i<10;i++){
              queue.offer(rand.nextInt(i+10));
             }
             System.out.println("1111"+queue.toString());
             printQ(queue);
             //public class LinkedList extends AbstractSequentialList implements List,Queue,Cloneable,Serializable
             Queue<Character> qc=new LinkedList<Character>();
             for(char c:"guoxzh".toCharArray()){
              qc.offer(c);
              System.out.println("qc=="+qc.toString());
             }
              printQ(qc);
            }
            
            public static void printQ(Queue queue){
             while(queue.peek()!=null){
              //peek和element都是在不移除的情況下返回對頭,但是peek在隊(duì)列為空的情況下返回null,element方法會(huì)拋出NoSuchElementException異常
              System.out.println(queue.remove());
              //remove和poll方法都是在移除并返回對頭,但是poll在為空時(shí)返回null,而remove會(huì)拋出NoSucheElementException異常
              System.out.println("2222"+queue.toString());
             }
            }
          }

          posted @ 2009-10-18 18:29 forgood 閱讀(209) | 評(píng)論 (0)編輯 收藏

          主站蜘蛛池模板: 泗水县| 福泉市| 康保县| 济宁市| 房产| 友谊县| 安远县| 绥宁县| 增城市| 丽江市| 安仁县| 图们市| 北京市| 德江县| 肥城市| 介休市| 咸宁市| 丰城市| 绥滨县| 邹城市| 班戈县| 杭锦旗| 县级市| 涿州市| 武平县| 延安市| 龙江县| 临朐县| 汝阳县| 娄底市| 天水市| 张北县| 曲麻莱县| 涿鹿县| 崇明县| 临邑县| 金门县| 北票市| 沙雅县| 长寿区| 建德市|