飛翔的起點(diǎn)

          從這里出發(fā)

          導(dǎo)航

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

          統(tǒng)計(jì)

          常用鏈接

          留言簿(5)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

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

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

          主站蜘蛛池模板: 云和县| 洪洞县| 屯留县| 高碑店市| 广河县| 高平市| 临城县| 东辽县| 宝清县| 古田县| 历史| 凤山县| 明水县| 延川县| 上杭县| 乌苏市| 彭州市| 抚宁县| 正阳县| 崇文区| 镇平县| 麟游县| 将乐县| 雷波县| 乐都县| 高密市| 洛扎县| 陇川县| 莎车县| 若羌县| 富蕴县| 花莲市| 银川市| 丹凤县| 台北县| 洪雅县| 高唐县| 原平市| 兰州市| 平原县| 东乡族自治县|