c bitset get
BitSet類的get()方法 (BitSet Class get() method)
Syntax:
句法:
public boolean get(int bit_in);
public BitSet get(int st_in, int en_in);
get() method is available in java.util package.
get()方法在java.util包中可用。
get(int bit_in) method is used to return the value of the given bit indices (bit_in). It returns true when the bit with the given index is set by using the set() method.
get(int bit_in)方法用于返回給定位索引(bit_in)的值。 當使用set()方法設置具有給定索引的位時,它返回true。
get(int st_in, int en_in) method is used to returns a subset consisted of bits from this BitSet from the given range st_in(starting index) and en_in(ending index).
get(int st_in,int en_in)方法用于從給定范圍st_in (起始索引)和en_in (結束索引)返回該BitSet中的位組成的子集。
get(int bit_in) method may throw an exception at the time of checking index.
在檢查索引時, get(int bit_in)方法可能會引發異常。
IndexOutOfBoundsException: This exception may throw when the given index is less than 0.
IndexOutOfBoundsException :當給定索引小于0時,可能引發此異常。
get(int st_in, int en_in) method may throw an exception at the time of checking exception.
在檢查異常時, get(int st_in,int en_in)方法可能會引發異常。
IndexOutOfBoundsException: This exception may throw when st_in or en_in is less than 0 or st_in > en_in.
IndexOutOfBoundsException :當st_in或en_in小于0或st_in> en_in時,可能引發此異常。
These are non-static methods, so it is accessible with the class object and if we try to access these methods with the class name then we will get an error.
這些是非靜態方法,因此可以通過類對象進行訪問,如果嘗試使用類名稱訪問這些方法,則會收到錯誤消息。
Parameter(s):
參數:
In the second case, get(int bit_in)
在第二種情況下, get(int bit_in)
- int bit_in – represents the bit index.
- int bit_in –表示位索引。
In the third case, get(int st_in, int en_in)
在第三種情況下, get(int st_in,int en_in)
- int st_in – represent the starting bit(st_in) to conclude.
- int st_in –表示要結束的起始位(st_in)。
Return value:
返回值:
In the first case, boolean get(bit_in): The return type of the method is boolean, it returns true when it returns the value of the bit of the given index.
在第一種情況下, boolean get(bit_in) :方法的返回類型為boolean ,當它返回給定索引的bit值時返回true。
In the second case, BitSet get(int st_in, int en_in), it returns BitSet of the given range (st_in & en_in).
在第二種情況下, BitSet get(int st_in,int en_in) ,它返回給定范圍( st_in&en_in )的BitSet。
Example:
例:
// Java program to demonstrate the example
// of get() method of BitSet.
import java.util.*;
public class GetOfBitSet {
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);
bs.set(60);
bs.set(70);
bs.set(80);
// Display Bitset
System.out.println("bs: " + bs);
// By using get(40) method is used to
// check the given bit exists in this BitSet or not
boolean status = bs.get(40);
// Display status
System.out.println("bs.get(40): " + status);
// By using get(40,60) method is used to
// check the given set of bits exists in this
// BitSet or not
// Display Bitset
System.out.println("bs.get(40,60): " + bs.get(40, 60));
}
}
Output
輸出量
bs: {10, 20, 30, 40, 50, 60, 70, 80}
bs.get(40): true
bs.get(40,60): {0, 10}
翻譯自: https://www.includehelp.com/java/bitset-get-method-with-example.aspx
c bitset get