飛翔的起點

          從這里出發

          導航

          <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 閱讀(217) 評論(0)  編輯  收藏 所屬分類: java

          主站蜘蛛池模板: 库伦旗| 永吉县| 文化| 莱芜市| 呼和浩特市| 册亨县| 襄汾县| 红安县| 阳江市| 阳泉市| 含山县| 阜宁县| 亳州市| 灯塔市| 沁阳市| 铜鼓县| 泰兴市| 商都县| 鄂尔多斯市| 修武县| 溧水县| 工布江达县| 宕昌县| 蒲城县| 民权县| 巴彦淖尔市| 灵石县| 九寨沟县| 睢宁县| 西充县| 普洱| 吉水县| 东兰县| 依兰县| 三明市| 阳山县| 宣汉县| 合川市| 喜德县| 玉林市| 余庆县|