Fastest way to check if a byte array is all zeros

前端 未结 5 766
栀梦
栀梦 2021-02-03 18:06

I have a byte[4096] and was wondering what the fastest way is to check if all values are zero?

Is there any way faster than doing:

byte[] b          


        
5条回答
  •  攒了一身酷
    2021-02-03 18:44

    This may not be the fastest or most memory performant solution but it's a one liner:

    byte[] arr = randomByteArray();
    assert Arrays.equals(arr, new byte[arr.length]);
    

提交回复
热议问题