BitSet get(int fromIndex,int toIndex) Method Example Program


Returns a new BitSet composed of bits from this BitSet from fromIndex (inclusive) to toIndex (exclusive).

Program

package com.candidjava;

import java.util.BitSet;

/**
 * @author : vinod kumar v
 * @description :The BitSet.get(int fromIndex,int toIndex) method returns a new
 *              BitSet composed of bits from this BitSet from fromIndex
 *              (inclusive) to toIndex (exclusive).
 * */

public final class BitSetgetFromToIndex {
	public static void main(String[] args) {

		BitSet obj = new BitSet(8);
		BitSet obj1 = new BitSet(8);

		obj.set(0);
		obj.set(1);
		obj.set(2);
		obj.set(3);

		obj1.set(2);
		obj1.set(4);
		obj1.set(6);
		obj1.set(8);

		System.out.println("The Value in obj:" + obj);
		System.out.println("The Value in obj1" + obj1);

		System.out.println("" + obj.get(2, 3));

		System.out.println("" + obj1.get(4, 8));

	}
}

Output

The Value in obj:{0, 1, 2, 3}
The Value in obj1{2, 4, 6, 8}
{0}
{0, 2}

Explanation

public BitSet get(int fromIndex, int toIndex)
Returns a new BitSet composed of bits from this BitSet from fromIndex (inclusive) to toIndex (exclusive).
Parameters:
fromIndex - index of the first bit to include
toIndex - index after the last bit to include
Returns:
a new BitSet from a range of this BitSet
Throws:
IndexOutOfBoundsException - if fromIndex is negative, or toIndex is negative, or fromIndex is larger than toIndex


Related Post

Comments


©candidjava.com