简体   繁体   中英

Convert byte [] to ArrayList<Object>

I have a byte [] that i obtained using Object ArrayList

Can anyone tell me how to convert my byte [] to Object ArrayList?

  • coveting arraylist like this

      ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = null; oos = new ObjectOutputStream(bos); oos.writeObject(mArrayList);//mArrayList is the array to convert byte[] buff = bos.toByteArray(); 

Thank you!

Now you've given us the information about how you did the conversion one way... you need:

ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes));
try {
    @SuppressWarnings("unchecked")
    ArrayList<Object> list = (ArrayList<Object>) ois.readObject();
    ...
} finally {
    ois.close();
}

I'm going to go with the obvious answer here...

for(byte b : bytearray) {
  arraylist.add(new Byte(b));
}

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