Reputation: 1
In my java class, one thing that we are often asked to do is to read in lines from a file that contain different data types (example String productName
, double price
, int quantity
, etc) and perform tasks with these objects. So for the example above we'd been working with the class Product(String productName, double price, int quantity)
. The only way that I have been able to do this is by storing them all in different ArrayLists
, which seems very inefficient. Can anyone provide some insight into a better way of doing this?
Upvotes: 0
Views: 299
Reputation: 593
Why not create class Product
and make it java.io.Serializable
.
In doing so, you can easily serialize the object to a file as well as de-serialize from a file to the object.
Upvotes: 1