serializable arraylist java code example
Example: how to serialize an arraylist in java
public class Serialize implements Serializable{
FileOutputStream fos= new FileOutputStream("filePath.txt");
ObjectOutputStream oos= new ObjectOutputStream(fos);
oos.writeObject(arrayListToBeWritten);
oos.close();
fos.close();
ArrayList<T> list;
FileInputStream fis = new FileInputStream("filePath.txt");
ObjectInputStream ois = new ObjectInputStream(fis);
list = (ArrayList) ois.readObject();
ois.close();
fis.close();
for (T temp: list) {
System.out.println(temp);
}