Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
BitSet stream() Method in Java with Examples
Next article icon

BitSet size() Method in Java with Examples

Last Updated : 27 Dec, 2018
Comments
Improve
Suggest changes
Like Article
Like
Report
The size() Method of BitSet class in Java is used to know the size of this BitSet. This size is equal to the number of bits, each element has occupied in the BitSet. The maximum element in the set is the size - the first element Syntax:
BitSet.hashCode()
Parameters: The method does not accept any parameters. Return Value: The method returns the number of bits present in the BitSet. Below programs are used to illustrate the working of BitSet.size() Method: Program 1: Java
// Java code to illustrate size() import java.util.*;  public class BitSet_Demo {     public static void main(String args[])     {         // Creating an empty BitSet         BitSet init_bitset = new BitSet();          // Use set() method to add elements into the Set         init_bitset.set(40);         init_bitset.set(25);         init_bitset.set(31);         init_bitset.set(100);         init_bitset.set(53);          // Displaying the BitSet         System.out.println("BitSet: " + init_bitset);          // Displaying the size         System.out.println("The size is: "                            + init_bitset.size());     } } 
Output:
  BitSet: {25, 31, 40, 53, 100}  The size is: 128  
Program 2: Java
// Java code to illustrate size() import java.util.*;  public class BitSet_Demo {     public static void main(String args[])     {         // Creating an empty BitSet         BitSet init_bitset = new BitSet();          // Displaying the BitSet         System.out.println("BitSet: " + init_bitset);          // Displaying the hashcode         System.out.println("The s iizes: "                            + init_bitset.size());     } } 
Output:
  BitSet: {}  The size is: 64  
Program 3: Java
// Java code to illustrate size() import java.util.*;  public class BitSet_Demo {     public static void main(String args[])     {         // Creating an empty BitSet         BitSet init_bitset = new BitSet();          // Use set() method to add elements into the Set         init_bitset.set(400);          // Displaying the BitSet         System.out.println("BitSet: " + init_bitset);          // Displaying the hashcode         System.out.println("The sizeis: " + init_bitset.size());     } } 
Output:
  BitSet: {400}  The size is: 448  

Next Article
BitSet stream() Method in Java with Examples
author
chinmoy lenka
Improve
Article Tags :
  • Misc
  • Java
  • Java - util package
  • Java-Functions
  • Java-BitSet
Practice Tags :
  • Java
  • Misc

Similar Reads

  • BitSet stream() Method in Java with Examples
    The stream() method of Java BitSet class is used to return a stream of indices for every bit contained in the BitSet. The indices are returned in increasing order. The size of the stream is the number of bits in the set state of the BitSet, which is equal to the value returned by the cardinality() m
    2 min read
  • AbstractSet size() method in Java with Example
    The size() method of AbstractSet in Java is used to get the size for this instance of the AbstractSet. It returns an integer value which is the size for this instance of the AbstractSet. Syntax: public int size() Parameters: This function has no parameters. Returns: The method returns an integer val
    2 min read
  • BitSet toString() Method in Java with Examples
    The java.util.BitSet.toString() is an inbuilt method of BitSet class that is used to get a string representation of the bits of the sets in the form of a set of entries separated by “, “. So basically the toString() method is used to convert all the elements of BitSet into String. In addition to thi
    2 min read
  • ArrayList size() Method in Java with Examples
    In Java, the size() method is used to get the number of elements in an ArrayList. Example 1: Here, we will use the size() method to get the number of elements in an ArrayList of integers. [GFGTABS] Java // Java program to demonstrate the use of // size() method for Integer ArrayList import java.util
    2 min read
  • AbstractMap size() Method in Java with Examples
    The AbstractMap.size() method of AbstractMap class is used to get the size of the map which refers to the number of the key-value pair or mappings in the Map. Syntax: AbstractMap.size() Parameters: The method does not take any parameters. Return Value: The method returns the size of the map which al
    2 min read
  • Dictionary size() Method in Java with Examples
    The size() Method of Dictionary class in Java is used to know the size of the dictionary or the number of distinct keys present in the dictionary. Syntax: DICTIONARY.size() Parameters: The method does not accept any parameters. Return Value: The method returns the number of keys present in the dicti
    2 min read
  • BitSet class methods in Java with Examples | Set 3
    BitSet class methods in Set 3. / / | | | \ \ and notand flip isEmpty equal get intersect BitSet class methods in Java with Examples | Set 2 BitSet class methods are explained as follows : and / notand : java.util.BitSet.and() and java.util.BitSet.notand() method is a java.util.Bitset class method. .
    5 min read
  • Map size() Method in Java With Examples
    Map size() method in Java is used to get the total number entries i.e, key-value pair. So this method is useful when you want total entries present on the map. If the map contains more than Integer.MAX_VALUE elements returnInteger.MAX_VALUE Syntax: int size(); Parameter: This method does not take an
    1 min read
  • BitSet clone() Method in Java with Examples
    The clone() Method Java.util.BitSet class is used to create a copy of an existing BitSet. The new BitSet is exactly equal to the existing one and is a mere copy of the previous BitSet. Syntax: Bit_Set.clone() Parameters: The method does not take any parameters. Return Value: The method just returns
    2 min read
  • BitSet length() Method in Java with Examples
    The length() Method of BitSet class in Java is used to know the logical size of this BitSet. This logical size is equal to the highest bit of the BitSet plus one. Syntax: BitSet.hashCode() Parameters: The method does not accept any parameters. Return Value: The method returns the logical size of the
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences