Java. Serialization an array -


lets supose define class

public class pointfloat { float x; float y; } 

then instantiate array

pointfloat[] points = new pointfloat[10]; 

at point have array of ten pointfloat objects. lets supose code assigns values x , y every pointfloats. need store array in varbinary in mysql database.

to accomplish need convert array of pointfloats byte[] can insert database using preparedstatement nothing new me use preparedstatement first time using objects serialization.

how convert array of pointfloat of size byte[]?. please keep simple possible.

thank reading.

you can use objectoutputstream write array bytearrayoutputstream. see answer details , example: https://stackoverflow.com/a/2836659/337621

since object contains 2 floats, standard serialization fits needs.


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -