Please can anyone tell me how to convert an ArrayList<Integer> to byte[]

Thank you

Integer values won't fit in a byte. Perhaps you could show a small example of what Integer values you expect, and how they should look after being converted?

Hi, guys this is what I tried.

        Object kTemp[] = kList.toArray();
        byte[] kByte = new byte[CHUNK];

        for(int i=0; i<CHUNK; i++){
            kByte[i] = kTemp.getBytes();
            System.out.println(kByte[i]);
        }

But I got an error

attack.java:180: cannot find symbol
symbol  : method getBytes()
location: class java.lang.Object[]
            kByte[i] = kTemp.getBytes();
                            ^
1 error

I also tried

        byte[] kByte = kList.getBytes();
        System.out.println(kByte);

and got the error

attack.java:177: cannot find symbol
symbol  : variable kList
location: class Attack
        byte[] kByte = kList.getBytes();
                       ^
1 error

Please can anyone suggest a way to get this done. Thank you

The compiler can not find definitions for some of the variables and methods you are using.
Where is the getBytes() method defined for an array?
Where is the variable: kList defined?

Where is the ArrayList<Integer>?

Edited 4 Years Ago by NormR1

This question has already been answered. Start a new discussion instead.