Java实现队列

 1 package Test;
 2 import java.util.*;
 3 public class Queue_test {
 4 
 5     public static void main(String[] args) {
 6         // TODO 自动生成的方法存根
 7         // 输入与字符处理
 8         Scanner scanner=new Scanner(System.in);
 9         String string=scanner.nextLine();
10         String [] string2=string.split("");
11         
12         //创建队列,并且将字符串插入队列里面
13         Queue<String> queue=new LinkedList<String>();
14         for(int i=0;i<string2.length;i++){
15             queue.add(string2[i]);
16         }
17         System.out.println("queue is: "+queue);
18         //移除队列元素
19         System.out.println("remove: "+ queue.remove());
20         System.out.println("queue is: "+queue);
21     }
22 
23 }

结果是:

abcdefg
queue is: [a, b, c, d, e, f, g]
remove: a
queue is: [b, c, d, e, f, g]
原文地址:https://www.cnblogs.com/heenhui2016/p/6166381.html