飛翔的起點

          從這里出發

          導航

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

          統計

          常用鏈接

          留言簿(5)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

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

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

          主站蜘蛛池模板: 长白| 马关县| 河北省| 伊金霍洛旗| 三亚市| 陵川县| 隆子县| 吉林市| 清水县| 九台市| 天长市| 宁南县| 永仁县| 互助| 连城县| 西贡区| 肇州县| 齐河县| 江都市| 昌乐县| 岳西县| 永和县| 和政县| 远安县| 闽侯县| 嘉善县| 托里县| 革吉县| 明光市| 舒城县| 紫阳县| 郓城县| 岳普湖县| 中卫市| 通许县| 阿勒泰市| 弋阳县| 合阳县| 金平| 长垣县| 濮阳市|