当前位置: 代码迷 >> 综合 >> java的Arrays.fill()方法对二维数组赋值boolean类型
  详细解决方案

java的Arrays.fill()方法对二维数组赋值boolean类型

热度:76   发布时间:2023-11-22 06:14:44.0

java的Arrays.fill()方法对二维数组赋值boolean类型

解决方案

import java.util.Arrays;
public class Test {
    	 public static void main(String[] args) {
    // TODO Auto-generated method stubboolean[][] 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 stubboolean[] vis = new boolean[10];//定义一个Boolean数组Arrays.fill(vis, false);Arrays.fill(vis,Boolean.FALSE);//或者}
}
  相关解决方案