- 阅读权限
- 255
- 威望
- 0 级
- 论坛币
- 50288 个
- 通用积分
- 83.6306
- 学术水平
- 253 点
- 热心指数
- 300 点
- 信用等级
- 208 点
- 经验
- 41518 点
- 帖子
- 3256
- 精华
- 14
- 在线时间
- 766 小时
- 注册时间
- 2006-5-4
- 最后登录
- 2022-11-6
已卖:4194份资源
院士
还不是VIP/贵宾
TA的文库 其他... Bayesian NewOccidental
Spatial Data Analysis
东西方数据挖掘
- 威望
- 0 级
- 论坛币
 - 50288 个
- 通用积分
- 83.6306
- 学术水平
- 253 点
- 热心指数
- 300 点
- 信用等级
- 208 点
- 经验
- 41518 点
- 帖子
- 3256
- 精华
- 14
- 在线时间
- 766 小时
- 注册时间
- 2006-5-4
- 最后登录
- 2022-11-6
|
经管之家送您一份
应届毕业生专属福利!
求职就业群
感谢您参与论坛问题回答
经管之家送您两个论坛币!
+2 论坛币
- /*
- Queue collection implements First-In Fist-Out behavior on items stored within it.
- */
- import java.util.*;
- public class QueueDemo {
- static String newLine = System.getProperty("line.separator");
- public static void main(String[] args) {
-
- System.out.println(newLine + "Queue in Java" + newLine);
- System.out.println("-----------------------" + newLine);
- System.out.println("Adding items to the Queue" + newLine);
- //Creating queue would require you to create instannce of LinkedList and assign
- //it to Queue
- //Object. You cannot create an instance of Queue as it is abstract
- Queue queue = new LinkedList();
-
- //you add elements to queue using add method
- queue.add("Java");
- queue.add(".NET");
- queue.add("Javascript");
- queue.add("HTML5");
- queue.add("Hadoop");
-
- System.out.println(newLine + "Items in the queue..." + queue + newLine);
- //You remove element from the queue using .remove method
- //This would remove the first element added to the queue, here Java
- System.out.println("remove element: " + queue.remove() + newLine);
-
- //.element() returns the current element in the queue, here when "java" is removed
- //the next most top element is .NET, so .NET would be printed.
- System.out.println("retrieve element: " + queue.element() + newLine);
-
- //.poll() method retrieves and removes the head of this queue
- //or return null if this queue is empty. Here .NET would be printed and then would
- //be removed
- //from the queue
- System.out.println("remove and retrieve element, null if empty: " + queue.poll() +
- newLine);
-
- //.peek() just returns the current element in the queue, null if empty
- //Here it will print Javascript as .NET is removed above
- System.out.println("retrieve element, null is empty " + queue.peek() + newLine);
- }
- }
复制代码
扫码加我 拉你入群
请注明:姓名-公司-职位
以便审核进群资格,未注明则拒绝
|
|
|