Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8540233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:33:02+00:00 2026-06-11T11:33:02+00:00

java.util.BitSet is backed by a long[] so the minimum size is 64 bits. I

  • 0

java.util.BitSet is backed by a long[] so the minimum size is 64 bits. I require to cache lots (~2M) of objects that each require a BitSet of size 23. Is there an alternative to BitSet that is more space efficient for small sizes? For example is there a BitSet type data structure that is backed by a byte[] instead of a long[]? This would allow me to store my 23 bits in 3 bytes instead of 8.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:33:03+00:00Added an answer on June 11, 2026 at 11:33 am

    The java.util.BitSet class is designed for larger bit sets. When you need bit sets of size 23, even a bit set based ob 3 bytes would use too much memory, because an array of any size uses an additional reference for the array itself, which is most likely four to eight bytes.

    The most economical solution in terms of memory is using ints instead of bit sets, and writing your own implementations of the bit set operations that you need. Since operations on bit sets are for the most part copied from bitwise operations, you should have no problem implementing them:

    boolean get(int mySet, int index) {
        return (mySet & (1<<index)) != 0;
    }
    int set(int mySet, int index) {
        return mySet | (1<<index);
    }
    int clear(int mySet, int index) {
        return mySet & (1<<index);
    }
    

    …and so on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a java.util.BitSet to store a dense vector of bits. I want
The java.util.Date toString() method displays the date in the local time zone. There are
java.util.Set specifies only methods that return all records (via Iterator or array). Why is
In java.util.Calendar , January is defined as month 0, not month 1. Is there
Using java.util.regex.Matcher , are the following expressions for matched1 and matched2 equivalent? Is there
Will java.util.UUID work for classes in Java? That is to say i have a
I am using java.util.concurrent.ExecutorService.submit(Callable<T>) to invoke Callable tasks that return void. The reason that
java.util.PriorityQueue allows a Comparator to be passed at construction time. When inserting elements, they
java.util.Date , java.util.Timetamp were seems to be causing great confusion for many. Within StackOverflow
java.util.Date date = new java.util.Date(); java.sql.Date today = new java.sql.Date(date.getTime()); //2012-03-23 java.sql.Time time =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.