简体   繁体   English

有没有办法在Java(Android)中将布尔数组打印为(0,1)

[英]Is there is any way to print boolean array as (0,1) in Java(Android)

I want to print boolean array as 0,1 in Java(Android) 我想在Java(Android)中将布尔数组打印为0,1

Now I print boolean[][] like this 现在我像这样打印boolean [] []

Arrays.deepToString(area.paints)

Result Sample 结果样本

[[true, false, true, false], [true, true, false, false]] [[true,false,true,false],[true,true,false,false]]

I want print like this 我要这样打印

[[1, 0, 1, 0],[1, 1, 0, 0]] [[1,0,1,0],[1,1,0,0]]

my boolean[][] is too big to check all values and return 0,1 我的boolean [] []太大,无法检查所有值并返回0,1

I need fastest method. 我需要最快的方法。

If you are just looking to print the array, why don't you just utilize String.replace() : 如果您只是想打印数组,为什么不使用String.replace()

boolean arr[][] = {{true, false, true, false}, {true, true, false, false}};
System.out.println(Arrays.deepToString(arr).replace("true", "1").replace("false", "0"));

This will give you the output 这会给你输出

[[1, 0, 1, 0], [1, 1, 0, 0]]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM