user3841581
user3841581

Reputation: 2747

Getting the length of a BiSet instance

I have a function which takes as argument a BiSet object. I have the following

public static void(String [] args)
{
   BitSet test = new BitSet(15);

     Store(test);
}

public void Store (BitSet a)
{
  boolean [] temp = new boolean[a.length()]();
  System.out.println(temp.length);
}

The problem is that the length of my temp or a is 64. How can I get the actual length (15) of the object instance test that I passed to the function Store?

Upvotes: 0

Views: 42

Answers (1)

shmosel
shmosel

Reputation: 50716

You can't. The constructor documentation says:

Creates a bit set whose initial size is large enough to explicitly represent bits with indices in the range 0 through nbits-1.

There's no guarantee that the initial size won't be larger than the requested size. In fact, nbits is lost by the time the constructor completes.

But there's really no reason you should need the initial size in real code.

Upvotes: 2

Related Questions