飛翔的起點

          從這里出發

          導航

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

          統計

          常用鏈接

          留言簿(5)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          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在隊列為空的情況下返回null,element方法會拋出NoSuchElementException異常
              System.out.println(queue.remove());
              //remove和poll方法都是在移除并返回對頭,但是poll在為空時返回null,而remove會拋出NoSucheElementException異常
              System.out.println("2222"+queue.toString());
             }
            }
          }

          posted on 2009-10-18 18:29 forgood 閱讀(219) 評論(0)  編輯  收藏 所屬分類: java

          主站蜘蛛池模板: 侯马市| 漳州市| 稷山县| 平远县| 彭山县| 南雄市| 洛扎县| 宿松县| 甘孜县| 偏关县| 安平县| 普陀区| 牡丹江市| 武平县| 天等县| 郸城县| 拉萨市| 蕉岭县| 巩义市| 宜兴市| 罗城| 峨眉山市| 汤阴县| 呼伦贝尔市| 白玉县| 锡林郭勒盟| 顺义区| 佛山市| 大厂| 保康县| 时尚| 濮阳县| 揭阳市| 堆龙德庆县| 新泰市| 鲁甸县| 桃园县| 成安县| 连云港市| 安福县| 宣城市|