简体   繁体   中英

How to deserialize an object of ArrayList<String[]> in java

I have serialized an ArrayList and stored it to a file with extension .ser . How can I deserialize the object and store it back into an ArrayList. I am getting an error Note: Hw5b.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. Note: Hw5b.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details.

//Serializing Object
ArrayList<String[]> list = new ArrayList<String []>();
FileOutputStream fout =  new FileOutputStream("movie-matrix2.ser");
ObjectOutputStream oos = new ObjectOutputStream(fout);
oos.writeObject(list);

//Deserializing Object
FileInputStream streamIn = new FileInputStream("movie-matrix2.ser");
ObjectInputStream objectInputStream =  new  ObjectInputStream(streamIn);
list = (ArrayList<String[]>)objectInputStream.readObject();

It's not an error. It's a warning.

For details, you could recompile with ecompile with -Xlint:unchecked, just as the message says.

But you can basically do nothing about that warning, except suppressing it: the compiler warns you that there is now way to ensure that the list you get is an ArrayList<String[]> . Only that it's an ArrayList.

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