weakhashmap_Java WeakHashMap size()方法与示例

weakhashmap

WeakHashMap类的size()方法 (WeakHashMap Class size() method)

  • size() method is available in java.util package.

    size()方法在java.util包中可用。

  • size() method is used to get the number of key-value pairs that exist in this map.

    size()方法用于获取此映射中存在的键值对的数量。

  • size() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    size()方法是一种非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • size() method does not throw an exception at the time of returning the size of this map.

    返回此地图的大小时, size()方法不会引发异常。

Syntax:

句法:

    public int size();

Parameter(s):

参数:

  • It does not accept any parameter.

    它不接受任何参数。

Return value:

返回值:

The return type of the method is int, it returns the cardinality (i.e. the number of key-value pair exists) of this map.

方法的返回类型为int ,它返回此映射的基数(即,存在键值对的数量)。

Example:

例:

// Java program to demonstrate the example 
// of int size() method of WeakHashMap 
import java.util.*;
public class SizeOfWeakHashMap {
public static void main(String[] args) {
// Instantiates a WeakHashMap object
Map < Integer, String > map = new WeakHashMap < Integer, String > ();
// By using put() method is to add
// key-value pairs in a WeakHashMap
map.put(10, "C");
map.put(20, "C++");
map.put(50, "JAVA");
map.put(40, "PHP");
map.put(30, "SFDC");
//Display WeakHashMap
System.out.println("WeakHashMap: " + map);
// By using size() method is to return
// the size of this WeakHashMap
int size = map.size();
// Display size
System.out.print("map.size(): " + size);
}
}

Output

输出量

WeakHashMap: {30=SFDC, 40=PHP, 10=C, 20=C++, 50=JAVA}
map.size(): 5

翻译自: https://www.includehelp.com/java/weakhashmap-size-method-with-example.aspx

weakhashmap

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/544340.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

扯一把 Spring 的三种注入方式,到底哪种注入方式最佳?

1. 实例的注入方式首先来看看 Spring 中的实例该如何注入&#xff0c;总结起来&#xff0c;无非三种&#xff1a;属性注入set 方法注入构造方法注入我们分别来看下。1.1 属性注入属性注入是大家最为常见也是使用最多的一种注入方式了&#xff0c;代码如下&#xff1a;Service p…

在项目中引入领域驱动设计的经验

Chris Patuzzo近期在一次演讲中介绍了领域驱动设计&#xff08;DDD&#xff09;的原则&#xff0c;并结合一个基于Ruby on Rails的真实项目进行讲解。在这次项目之前&#xff0c;Chris所在的团队为重新设计公司的主营网站所做的两个概念验证都因为可伸缩性方面的问题而失败了。…

Redis笔记之基本数据结构 链表

链表 链表具有空间存储不连续&#xff0c;增删节点快的优点&#xff0c;因此redis在列表键、发布与订阅、慢查询、监视器等使用了链表作为底层实现。由于C语言中没有内置的链表实现&#xff0c;因此redis自己进行了实现。 双向链表。每个listtNode都有perv和next指针&#x…

treeset java_Java TreeSet iterator()方法与示例

treeset javaTreeSet类的iterator()方法 (TreeSet Class iterator() method) iterator() method is available in java.util package. iterator()方法在java.util包中可用。 iterator() method is used to iterate the elements of this TreeSet is ascending or increasing or…

SpringCloud组件:Ribbon负载均衡策略及执行原理!

大家好&#xff0c;我是磊哥。今天我们来看下微服务中非常重要的一个组件&#xff1a;Ribbon。它作为负载均衡器在分布式网络中扮演着非常重要的角色。本篇主要内容如下&#xff1a;在介绍 Ribbon 之前&#xff0c;不得不说下负载均衡这个比较偏僻的名词。为什么说它偏僻了&…

Redis笔记之基本数据结构 字典

字典 符号表、关联数组或者映射&#xff0c;有点类似于java中的map&#xff0c;用于保存键值对key-value。字典中的键key是独一无二的。底层实现为哈希表。下面进行简述&#xff1a; 哈希表。哈希表主要包含table数组、size、sizemask以及used。table用于保存哈希表节点&…

【零基础学习iOS开发】【02-C语言】02-第一个C语言程序

本文目录 前言一、编写第一个C语言程序-Hello World二、编译程序三、链接程序四、运行程序五、总结六、学习建议七、clang指令汇总回到顶部前言 前面已经唠叨了这么多理论知识&#xff0c;从这讲开始&#xff0c;就要通过接触代码来学习C语言的语法。学习任何一门语言&#xff…

安卓平板体验Java开发,还能白嫖一年阿里无影云,真香!(内含白嫖方法,人人可领)...

作者 | 磊哥来源 | Java中文社群&#xff08;ID&#xff1a;javacn666&#xff09;转载请联系授权&#xff08;微信ID&#xff1a;GG_Stone&#xff09;阿里无影云早有耳闻&#xff0c;前两天看朋友发体验照片&#xff0c;可能是程序员天生爱折腾的特性又发挥作用了&#xff0c…

Linux命令(三)

echo&#xff1a;输出信息echo ”abc”echo “字符串” |passwd --stdin USERNAME :利用管道修改用户密码输出重定向&#xff1a;>覆盖输出&#xff08;会覆盖原文件中的内容&#xff09;>>追加输出 &#xff08;原有内容会被保留&#xff09;Set –c &#xff1a…

strictmath_Java StrictMath scalb()方法与示例

strictmathStrictMath类scalb()方法 (StrictMath Class scalb() method) Syntax: 句法&#xff1a; public static double scalb(double do , int sf);public static float scalb(float fl , int sf);scalb(double do , int sf) method is used to return do* 2 raised to the…

你知道group by的工作原理和优化思路吗?

前言 日常开发中&#xff0c;我们经常会使用到group by。亲爱的小伙伴&#xff0c;你是否知道group by的工作原理呢&#xff1f;group by和having有什么区别呢&#xff1f;group by的优化思路是怎样的呢&#xff1f;使用group by有哪些需要注意的问题呢&#xff1f;本文将跟大家…

strictmath_Java StrictMath hypot()方法与示例

strictmathStrictMath类hypot()方法 (StrictMath Class hypot() method) hypot() method is available in java.lang package. hypot()方法在java.lang包中可用。 hypot() method is used to return the square root of sqrt(sq(d1)sq(d2)) without any intermediate operation…

关Jquery判断input type=checkbox元素是否被选中的判断

2019独角兽企业重金招聘Python工程师标准>>> 在用到复选框的时候&#xff0c;想在js中判断chekbox是否被选中 <input name"isPermit" id"isPermit" type"checkbox"> 百度了很多的判断方法 1、 if($("#isPermit").att…

Redis夺命十二问,你能扛到第几问?

Redis是面试中绕不过的槛&#xff0c;只要在简历中写了用过Redis&#xff0c;肯定逃不过。今天我们就来模拟一下面试官在Redis这个话题上是如何一步一步深入&#xff0c;全面考察候选人对于Redis的掌握情况。小张&#xff1a;面试官&#xff0c;你好。我是来参加面试的。面试官…

Java Scanner nextLine()方法与示例

扫描仪类nextLine()方法 (Scanner Class nextLine() method) nextLine() method is available in java.util package. nextLine()方法在java.util包中可用。 nextLine() method is used to get the skipped line. nextLine()方法用于获取跳过的行。 nextLine() method is a non…

bzoj 1192

http://www.lydsy.com/JudgeOnline/problem.php?id1192 好像学过一个东西&#xff1a; [0..2^(N1)-1]内的数都的都可以由2^0,2^1,...,2^N这N1个数中若干个相加得到。 #include<cstdio> #include<cstdlib> #include<iostream> #include<fstream> #incl…

Spring Boot Admin 报警提醒和登录验证功能实现!

作者 | 磊哥来源 | Java中文社群&#xff08;ID&#xff1a;javacn666&#xff09;转载请联系授权&#xff08;微信ID&#xff1a;GG_Stone&#xff09;Spring Boot Admin&#xff08;SBA&#xff09;是一个开源的社区项目&#xff0c;用于管理和监控 Spring Boot 应用程序&…

Java Hashtable rehash()方法与示例

哈希表类rehash()方法 (Hashtable Class rehash() method) rehash() method is available in java.util package. rehash()方法在java.util包中可用。 rehash() method is used to extend the capacity and it is invoked implicitly if the number of keys limit exceeds hash…

企业Shell面试题18:单词及字母去重排序案例

1、按单词出现频率降序排序&#xff01; 2、按字母出现频率降序排序&#xff01; the squid project provides a number of resources to assist users design,implement and support squid installations. Please browse the documentation and support sections for more inf…

5种高大上的yml读取方式,你知道几种?

我们今天就来点实战&#xff0c;总结一下除了烂大街的Value和ConfigurationProperties外&#xff0c;还有哪些读取yml配置文件的方法&#xff1f;1、Environment在Spring中有一个类Environment&#xff0c;它可以被认为是当前应用程序正在运行的环境&#xff0c;它继承了Proper…