I have an arraylist of class Room
which is held in class Hostel
, i would like to write this arraylist to a text file. What is the most efficient method of doing so?
Hostel Class
public class Hostel
{
private ArrayList < Room > rooms;
}
Room Class
abstract class Room
{
public Room(int newRoomNo, boolean newRoomEnSuite, int newRoomNights, String newRoomBooker)
{
roomNo = newRoomNo;
roomEnSuite = newRoomEnSuite;
roomBooking = "Booked";
roomNights = newRoomNights;
roomBooker = newRoomBooker;
}
}
A one-liner from commons-io
FileUtils.writeLines(new File(path), list);