简体   繁体   中英

How do I declare an array of bytes in Java?

I have an algorithm written in Delphi and ask me to convert that to java equivalent.

It has a line of code that I can't understand, could anyone help me convert this line of code to java ?!

const list: array [1..37] of byte=(9,7,5,3,1,2,4,6,8,4,7,3,9,1,6,5,1,6,7,2,3,6,5,3,8,9,2,1,7,4,2,3,1,9,7,6,8);

First you will need to import Collection framework by declaring import java.util.*;

    byte data [] = {9,7,5,3,1,2,4,6,8,4,7,3,9,1,6,5,1,6,7,2,3,6,5,3,8,9,2,1,7,4,2,3,1,9,7,6,8};
    List<byte[]> list = new ArrayList<byte[]>(Arrays.asList(data));

    // outputting your data
    for(byte [] arrayOfByte : list){
    for( byte element : arrayOfByte){
    System.out.println(element);
    }
   }

If you don't want to use collection Framework then , simply :

    byte list [] = {9,7,5,3,1,2,4,6,8,4,7,3,9,1,6,5,1,6,7,2,3,6,5,3,8,9,2,1,7,4,2,3,1,9,7,6,8};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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