I’m pretty new to Java, and I’m writing a program that needs to store:
- Customer data
- Product data
In separate lists.
I’ve tried with HashMap, hashtable as well as ArrayList of old, but it gets really messy when I’ve got to store, for example, the product name (Str), selling price (int), buying price (int), a description (Str) and a product type (boolean). I’ve been looking at JDBC, but it looks really complicated to set up, but I’ll try either that or java.sql if there’s no other way.
What I’m looking for is a kind of HashMap that allows more “rows”.
Create a class that will model the entity you need to store:
Then you can use any Collection to store them:
You may also want to consider an ORM solution. This will make database handling a lot easier.