[英]what is the purpose of BitSet valueOf in fromString method
I would appreciate an explanation of what this line does exactly. 我希望能对此行的确切解释进行解释。
BitSet.valueOf(new long[] { Long.parseLong(s, 2) });
While this code example posted by FauxFaus really helped me understand BitSet usage, I don't find the purpose of the above line or why. 虽然FauxFaus发布的此代码示例确实帮助我了解了BitSet的用法,但我找不到上一行的目的或原因。 here is the full example: 这是完整的示例:
package com.tutorialspoint;
import java.util.*;
import java.util.BitSet;
public class TimeZoneDemo {
public static void main(String[] args) {
BitSet bits1 = fromString("1000001");
BitSet bits2 = fromString("1111111");
System.out.println(toString(bits1)); // prints 1000001
System.out.println(toString(bits2)); // prints 1111111
bits2.and(bits1);
System.out.println(toString(bits2)); // prints 1000001
}
private static BitSet fromString(final String s) {
System.out.println(BitSet.valueOf(new long[] { Long.parseLong(s, 2) }));
return BitSet.valueOf(new long[] { Long.parseLong(s, 2) });
}
private static String toString(BitSet bs) {
return Long.toString(bs.toLongArray()[0], 2);
}
}
Please note that I can't comment on the original answer to ask the OP. 请注意,我无法对原始答案发表评论以问问OP。
Long.parseLong(s, 2)
parses the String
s
as a binary String
. Long.parseLong(s, 2)
解析String
s
作为二进制String
。 The resulting long
is put in a long
array and passed to BitSet.valueOf
to generate a BitSet
whose bits represent the bits of that long
value. 生成的long
放入long
数组中,并传递到BitSet.valueOf
以生成BitSet
其位表示该long
值的位。
The reason BitSet.valueOf
takes long
array instead of a single long
is to allow creation of BitSet
s having more than 64 bits. BitSet.valueOf
采用long
数组而不是单个long
是允许创建具有64位以上的BitSet
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.