How to send HashMap using DatagramPacket?

I know I can send ArrayList to ip using below code.

List list = new ArrayList();
ByteArrayOutputStream out = new ByteArrayOutputStream();
ObjectOutputStream outputStream = new ObjectOutputStream(out);
outputStream.writeObject(list);
outputStream.close();

byte[] listData = out.toByteArray();

      

When I replace the list with a HashMap, why doesn't it work? How can I send a HashMap if I cannot send it that way?

+3


source to share





All Articles