java queue size_Java中的PriorityQueue size() 方法 - Break易站

news/2024/7/2 23:15:24

Java.util.PriorityQueue.size()方法用于获取PriorityQueue的大小或PriorityQueue中存在的元素数。

句法:

Priority_Queue.size()

参数:此方法不带任何参数。

返回值:该方法返回PriorityQueue中存在的元素的大小或数量。

下面的程序说明了Java.util.PriorityQueue.size()方法

程序1:

// Java code to illustrate size()

import java.util.*;

public class PriorityQueueDemo {

public static void main(String args[])

{

// Creating an empty PriorityQueue

PriorityQueue queue = new PriorityQueue();

// Use add() method to add elements into the Queue

queue.add("Welcome");

queue.add("To");

queue.add("Geeks");

queue.add("For");

queue.add("Geeks");

// Displaying the PriorityQueue

System.out.println("PriorityQueue: " + queue);

// Displaying the size of the PriorityQueue

System.out.println("The size of the queue is: " + queue.size());

}

}

输出:

PriorityQueue: [For, Geeks, To, Welcome, Geeks]

The size of the queue is: 5

程序2:

// Java code to illustrate size()

import java.util.*;

public class PriorityQueueDemo {

public static void main(String args[])

{

// Creating an empty PriorityQueue

PriorityQueue queue = new PriorityQueue();

// Use add() method to add elements into the Queue

queue.add(10);

queue.add(15);

queue.add(30);

queue.add(20);

queue.add(5);

queue.add(18);

// Displaying the PriorityQueue

System.out.println("PriorityQueue: " + queue);

// Displaying the size of the PriorityQueue

System.out.println("The size of the queue is: " + queue.size());

}

}

输出:

PriorityQueue: [5, 10, 18, 20, 15, 30]

The size of the queue is: 6


http://lihuaxi.xjx100.cn/news/270028.html

相关文章

[转载]分享WCF聊天程序--WCFChat

http://www.cnblogs.com/gaoweipeng/archive/2009/09/04/1560260.html 无意中在一个国外的站点下到了一个利用WCF实现聊天的程序,作者是:Nikola Paljetak。研究了一下,自己做了测试和部分修改,感觉还不错,分享给大家。…

国内外优秀的计算机视觉团队汇总

点击上方“小白学视觉”,选择加"星标"或“置顶”重磅干货,第一时间送达名单不完全,原文链接:http://bbs.cvmart.net/topics/481/outstanding-Computer-Vision-Team原帖含蓝色关键词链接还有哪些牛CV实验室,欢…

Spring Boot 打包不同环境配置与 Shell 脚本部署

点击上方蓝色“方志朋”,选择“设为星标”回复“666”获取独家整理的学习资料!本篇和大家分享的是 Spring Boot 打包并结合 Shell 脚本命令部署,重点在分享一个shell 程序启动工具,希望能便利工作;profiles指定不同环境…

姚班大神胡渊鸣回国创业!超一半员工为清华校友,团队人均竞赛金牌数≥2

点击上方“视学算法”,选择加"星标"或“置顶”重磅干货,第一时间送达杨净 边策 发自 凹非寺 量子位 报道 | 公众号 QbitAI清华姚班出身的“计算机图形学超级新星”胡渊鸣同学回国创业啦!胡渊鸣,何许人也?他是…

信息安全系统设计基础家庭作业

《深入理解计算机系统》家庭作业 * 8.9 答案: 进程对 是否并发 AB 否 AC 是 AD 是 BC 是 BD 是 CD 是 * 8.10 答案: A. 调用一次,返回两次: fork B. 调用一次,从不返回: execve, longjmp C. 调…

漫画 | 程序媛小姐姐带你一次了解什么是排序算法

来源 | 小齐本齐封图 | CSDN 付费下载自视觉中国插入排序借用《算法导论》里的例子,就是我们打牌的时候,每新拿一张牌都会把它按顺序插入,这,其实就是插入排序。齐姐声明:虽然我们用打牌的例子,但是可不能学…

[Python] 练习代码

# from random import randrange # num int(input(摇几次骰子: )) # sidesint(input(筛子有几个面: )) # sum0 # for i in range(num): # sum randrange(sides)1 # print(最终的点数和是 ,sum,平均点数是:,sum/num)# from random import shuffle # from pprint import ppr…

java开发人员技术提升_Java开发初学者如何快速提升编程能力

原标题:Java开发初学者如何快速提升编程能力2019年如何才能学好Java开发?初学者需要注意哪些问题?技术的学习很多人都会有一个共同的问题,那就是该如何选择一门技术学习,或者说如何选择一门编程语言学习,部分人之所以…