我想要一个包含 n 组整数的列表,最初这个列表应该用 null 填充。许多 Sets 将在稍后初始化,有些将保持为 null。
我尝试了不同的方法来实现这一点,其中一些包括在这里:
List<HashSet<Integer>> List_of_Sets = Arrays.asList(new HashSet[n]);
Run Code Online (Sandbox Code Playgroud)
ArrayList<HashSet<Integer>> List_of_Sets = new ArrayList<>(n);
while(n-- > 0) List_of_Sets.add(null);
Run Code Online (Sandbox Code Playgroud)
有没有更快的方法来做到这一点?
为了澄清起见,将Arrays.fill()使用数组示例比:
/*
* initialize a smaller piece of the array and use the System.arraycopy
* call to fill in the rest of the array in an expanding binary fashion
*/
public static void bytefill(byte[] array, byte value) {
int len = array.length;
if (len > 0){
array[0] = value;
}
//Value of i …Run Code Online (Sandbox Code Playgroud)