java的Arrays.fill()方法对二维数组赋值boolean类型
解决方案
import java.util.Arrays;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
boolean[][] vis = new boolean[10][10];
for (int m= 0; m < 10; m++) {//对m行进行赋值
Arrays.fill(vis[m], false);
}
}
}
java的Arrays.fill()方法对一维数组赋值
Arrays.fill(vis, false);
/**
* Assigns the specified Object reference to each element of the specified
* array of Objects.
*
* @param a the array to be filled
* @param val the value to be stored in all elements of the array
* @throws ArrayStoreException if the specified value is not of a
* runtime type that can be stored in the specified array
*/
public static void fill(Object[] a, Object val) {
for (int i = 0, len = a.length; i < len; i++)
a[i] = val;
}
所以它里面只能对一维数组赋值
import java.util.Arrays;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
boolean[] vis = new boolean[10];//定义一个Boolean数组
Arrays.fill(vis, false);
Arrays.fill(vis,Boolean.FALSE);//或者
}
}