楼主: Lisrelchen
942 2

【独家发布】[Case Study]How to Use Que in Java [推广有奖]

  • 0关注
  • 62粉丝

VIP

已卖:4194份资源

院士

67%

还不是VIP/贵宾

-

TA的文库  其他...

Bayesian NewOccidental

Spatial Data Analysis

东西方数据挖掘

威望
0
论坛币
50288 个
通用积分
83.6306
学术水平
253 点
热心指数
300 点
信用等级
208 点
经验
41518 点
帖子
3256
精华
14
在线时间
766 小时
注册时间
2006-5-4
最后登录
2022-11-6

楼主
Lisrelchen 发表于 2016-8-31 23:37:54 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
  1. /*
  2. Queue collection implements First-In Fist-Out behavior on items stored within it.
  3. */
  4. import java.util.*;
  5. public class QueueDemo {
  6.   static String newLine = System.getProperty("line.separator");
  7.   public static void main(String[] args) {
  8.   
  9.     System.out.println(newLine + "Queue in Java" + newLine);
  10.     System.out.println("-----------------------" + newLine);
  11.     System.out.println("Adding items to the Queue" + newLine);
  12.     //Creating queue would require you to create instannce of LinkedList and assign
  13.     //it to Queue
  14.     //Object. You cannot create an instance of Queue as it is abstract
  15.     Queue queue = new LinkedList();
  16.    
  17.     //you add elements to queue using add method
  18.     queue.add("Java");
  19.     queue.add(".NET");

  20.     queue.add("Javascript");
  21.     queue.add("HTML5");
  22.     queue.add("Hadoop");
  23.    
  24.     System.out.println(newLine + "Items in the queue..." + queue + newLine);

  25.     //You remove element from the queue using .remove method
  26.     //This would remove the first element added to the queue, here Java
  27.     System.out.println("remove element: " + queue.remove() + newLine);
  28.    
  29.     //.element() returns the current element in the queue, here when "java" is removed
  30.     //the next most top element is .NET, so .NET would be printed.
  31.     System.out.println("retrieve element: " + queue.element() + newLine);
  32.    
  33.     //.poll() method retrieves and removes the head of this queue
  34.     //or return null if this queue is empty. Here .NET would be printed and then would
  35.     //be removed
  36.     //from the queue
  37.     System.out.println("remove and retrieve element, null if empty: " + queue.poll() +
  38.     newLine);
  39.    
  40.     //.peek() just returns the current element in the queue, null if empty
  41.     //Here it will print Javascript as .NET is removed above
  42.     System.out.println("retrieve element, null is empty " + queue.peek() + newLine);
  43.   }
  44. }
复制代码


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Case study study Java Case use collection require Object public create

本帖被以下文库推荐

沙发
Lisrelchen 发表于 2016-8-31 23:38:53
  1. Executing Run Command: java -classpath /root QueueDemo                                                                                                                                                                                                                                                               
  2.                                                                                                                                                                                                                                                                                                                        
  3.                                                                                                                                                                                                                                                                                                                        
  4. Queue in Java                                                                                                                                                                                                                                                                                                         
  5.                                                                                                                                                                                                                                                                                                                        
  6. -----------------------                                                                                                                                                                                                                                                                                                
  7.                                                                                                                                                                                                                                                                                                                        
  8. Adding items to the Queue                                                                                                                                                                                                                                                                                             
  9.                                                                                                                                                                                                                                                                                                                        
  10.                                                                                                                                                                                                                                                                                                                        
  11. Items in the queue...[Java, .NET, Javascript, HTML5, Hadoop]                                                                                                                                                                                                                                                           
  12.                                                                                                                                                                                                                                                                                                                        
  13. remove element: Java                                                                                                                                                                                                                                                                                                   
  14.                                                                                                                                                                                                                                                                                                                        
  15. retrieve element: .NET                                                                                                                                                                                                                                                                                                
  16.                                                                                                                                                                                                                                                                                                                        
  17. remove and retrieve element, null if empty: .NET                                                                                                                                                                                                                                                                       
  18.                                                                                                                                                                                                                                                                                                                        
  19. retrieve element, null is empty Javascript                                                                                                                                                                                                                                                                             
  20.                                                                                                                                                                                                                                                                                                                        
  21.                                                                                                                                                                                                                                                                                                                        
  22. Process exited successfully      
复制代码

藤椅
Kamize 学生认证  发表于 2016-9-1 07:33:26 来自手机
Lisrelchen 发表于 2016-8-31 23:37
谢谢分享

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
jg-xs1
拉您进交流群
GMT+8, 2026-1-1 22:00