java bitset_Java BitSet cardinality()方法与示例

java bitset

BitSet类cardinality()方法 (BitSet Class cardinality() method)

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

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

  • cardinality() method is used to return the cardinality (i.e. the number of bits is set to true by using set() method ) in this Bitset.

    cardinality()方法用于返回此Bitset中的基数(即,通过使用set()方法将位数设置为true)。

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

    cardinality()方法是一种非静态方法,因此可以通过类对象进行访问,如果尝试使用类名称访问该方法,则会收到错误消息。

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

    返回此Bitset的基数时, cardinality()方法不会引发异常。

Syntax:

句法:

    public int cardinality();

Parameter(s):

参数:

  • It does not accept any parameter.

    它不接受任何参数。

Return value:

返回值:

The return type of this method is int, it returns the cardinality of this Bitset.

此方法的返回类型为int ,它返回此Bitset的基数。

Example:

例:

// Java program to demonstrate the example 
// of int cardinality() method of BitSet.
import java.util.*;
public class CardinalityOfBitSet {
public static void main(String[] args) {
// create an object of BitSet
BitSet bs = new BitSet(10);
// By using set() method is to set
// the values in BitSet 
bs.set(10);
bs.set(20);
bs.set(30);
bs.set(40);
bs.set(50);
// Display Bitset
System.out.println("bs :" + bs);
// By using cardinality() method is to return
// the number of bits in this BitSet
int cardinality = bs.cardinality();
// Display BitSet 2
System.out.println("bs.cardinality()  : " + cardinality);
}
}

Output

输出量

bs :{10, 20, 30, 40, 50}
bs.cardinality()  : 5

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

java bitset

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

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

相关文章

LeetCode: Merge k Sorted Lists

自己写的太复杂了,一开始想的是给开始的lists头们排序,然后从这个序列的第一个抽出来,然后再重新用二分法进行排序,不过这个方法large超时了,看了网上的发现还是用很土地方法用一个for循环从前两个开始merge到最后&…

JAVA 取得当前目录的路径

在写java程序时不可避免要获取文件的路径...总结一下,遗漏的随时补上 1.可以在servlet的init方法里 String path getServletContext().getRealPath("/"); 这将获取web项目的全路径 例如 :E:/eclipseM9/workspace/tree/ tree是我web项目的根目录 2.你也可以随时在任意…

golang mysql curd_Go 语言操作 MySQL 之 CURD 操作

本文转载于SegmentFault社区作者:Meng小羽MySQL 是目前开发中最常见的关系型数据库,使用 Go 语言进行操控数据库需要使用 Go 自带database/sql和驱动go-sql-driver/mysql来实现。创建好 Go 项目,需要引用驱动依赖:go get -u githu…

02.1-元素定位(find)

常用的一些方法 一、导包 from selenium import webdriver二、打开火狐(空白页) b webdriver.Firefox()三、跳转到指定的网站 b.get(https://www.baidu.com/)四、将浏览器页面最大化 b.maximize_window()五、通过F12可查看当前的贴吧为超链接形式 …

快速傅里叶变换(FFT)——按时间抽取DIT的基

目录【1】前言1、DIF计算量2、利用性质改善【2】公式推导1、N 到 2*N/2a、分解原序列b、分解后的DFT变换c、一系列化简操作之后d、蝶形信号流e、计算量总结2、N/2 到 2*N/4a、分解X2(k)序列b、蝶形信号流(2列)3、N/4 到 2*N/8a、蝶形信号流(3…

Python字符串| 带示例的format()方法

String.format()方法 (String.format() Method) format() method is used to format the string (in other words - we can say to achieve the functionality like printf() in C language). format()方法用于格式化字符串(换句话说,我们可以说实现了C语言中类似于…

PLSQL Developer使用技巧

1、PL/SQL Developer记住登陆密码在使用PL/SQL Developer时,为了工作方便希望PL/SQL Developer记住登录Oracle的用户名和密码;设置方法:PL/SQL Developer 7.1.2 ->tools->Preferences->Oracle->Logon History , “St…

3月份的总结

租房子找了个黑中介,各种扣钱,合租的违约了,押金不要了直接一走了之,水费我们承担,中介这会儿又把责任推得一干二净,还耍小聪明,非说我是两个人住的,各种费用要交两份。。。我一时气…

快速傅里叶变换(FFT)——按频率抽取DIF的基

目录【1】回顾DIT【2】算法原理【3】运算特点【1】回顾DIT https://blog.csdn.net/qq_42604176/article/details/105559756 【2】算法原理 设序列点数:N2^M,M为正整数。将输入序列按照前一半、后一半分开。(并非按照奇偶分) 由于&#xf…

02.2-元素定位(XPath)

XML路径语言用来确定XML文档中某部分位置的语言XPath用于在XML文档中通过元素和属性进行导航XPath遵守W3C标准XPath节点类型: 元素、属性、文本、命名空间、指令处理、注释、文档 通过路径表达式从XML文档中选取节点或节点设置 表达式结果说明/xxx选取根节点xxx/xx…

android ImageView 之 android:scaleTye=

原文:http://juliaailse.iteye.com/blog/1409317 1、scaleType“matrix” 是保持原图大小、从左上角的点开始,以矩阵形式绘图。 2、scaleType“fitXY” 是将原图进行横方向(即XY方向)的拉伸后绘制的。 3、scaleType“fitStart…

acquire方法_Python锁类| 带有示例的acquire()方法

acquire方法Python Lock.acquire()方法 (Python Lock.acquire() Method) acquire() is an inbuilt method of the Lock class of the threading module in Python. acquisition()是Python中线程模块的Lock类的内置方法。 This method is used to acquire a lock, either block…

VSS2008 安装silverlight3.0步骤

需要的Q我359273753 我是新手不知道在哪里上传附件 汗一个转载于:https://www.cnblogs.com/ganler1988/archive/2011/03/17/1987367.html

php字符串对象,PHP字符串到对象名称

好的我有一个字符串……$a_string "Product";我想在调用这样的对象时使用这个字符串:$this->$a_string->some_function();狄更斯如何动态调用该对象?(不要以为我在PHP 5心中)解决方法:所以你要使用的代码是:$a_string &quo…

莫比乌斯函数---C++

【问题描述】 莫比乌斯函数,数论函数,由德国数学家和天文学家莫比乌斯(Mobius,1790-1868)提出。梅滕斯(Mertens)首先使用μ(n)作为莫比乌斯函数的记号。而据说,高斯(Gauss)比莫比乌斯早三十年就曾考虑过这个函数。莫比乌斯函数在数…

Opencv——findContours函数再探(由轮廓联想连通域)

目录关于调参的一些思考分析图像的一些角度面积、周长、矩形度、圆形度、宽长比例1:找出汽车轮毂圆孔(从轮廓和连通域两个角度)例2:找出芯片中间正方形物体例3:桌面上橘色物体总结关于调参的一些思考 合理的参数设置&…

stl vector 函数_vector :: crend()函数以及C ++ STL中的示例

stl vector 函数C vector :: crend()函数 (C vector::crend() function) vector::crend() is a library function of "vector" header, it is used to get the first element of a vector from reverse ending, it returns a const reverse iterator pointing to th…

.Net DateTime.ToString 格式化输出 (转载)

原文 虽然 System.DateTime 本身已经具有了不少现成的格式化输出,例如: ToLongDateString, ToShortTimeString, ToUniversalTime 等,但是却远远不能满足我们实际的需要,这就要用到了 DateTime.ToString,就要提到 DateT…

modelsim 编译 xilinx库

1.为单个工程加入库 在某一个目录建立工程 然后 vlib unisim vcom -work unsim *.vhd 然后就加入了unisim库 如果是windows的话,工程文件mpf应该是记录了这个库的信息,所以重新打开这个工程时,依然有这个库 linux,不用gui界面…

php 字符串匹配 like,ThinkPHP like模糊查询,like多匹配查询,between查询,in查询,一般查询书写方法...

搜索热词ThinkPHP的数据库条件查询语句有字符串式,数组式书写方法字符串式即是原生式,数组式查询语句因书写方式与特定字符的原因比较复杂,下面为大家例出了常用的ThinkPHP数组式查询语句的使用方法ThinkPHP一般查询$data_gt[id]array(gt,8);…