简体   繁体   English

遍历字节数组-Java

[英]Looping through byte array - java

I would like to try and loop through this following byte array: 我想尝试遍历以下字节数组:

public byte[] mFFTBytes;

How would I go about doing this in java with a for loop? 我将如何使用for循环在Java中执行此操作?

Thanks in advance! 提前致谢!

First of all you need to instantiate your array because you will have null pointer exceptions all over the place. 首先,您需要实例化数组,因为到处都是空指针异常。

Then you can use a for each loop 然后您可以为每个循环使用

for(byte b : mFFTBytes){
    System.out.println(b);
}

I am not sure if I understand well what you are asking for. 我不确定我是否理解您的要求。 Going through any array in Java is quite trivial action like: 遍历Java中的任何数组都是非常简单的操作,例如:

        for (byte myByte: mFFTBytes) {
            //do something with myByte
        }

or 要么

        for (int i=0;i<mFFTBytes.length;i++) {
            //do something with mFFTBytes[i]
        }

The latter should be faster, but for a vast majority of applications is does not matter much. 后者应该更快,但是对于绝大多数应用程序来说并没有太大关系。

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

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