Thread: Storing Data
View Single Post
  #2 (permalink)  
Old 08-03-2007, 07:48 AM
hardwired hardwired is offline
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
A fascinating question because there are so many possibilities.
Some suggestions:
A List (LinkedList, ArrayList, etc) can take any kind of object including another List, an array (or multi-dimensional array) or a custom class object.
A "Data Store" class can have any thing you want in it along with methods such as write or draw.
For instance:
Code:
class PseudoStore { String name; int id; public PseudoStore(String name, int id) { this.name = name; this.id = id; } public String toString() { return "PseudoStore[name:" + name + ", id:" + id + "]"; } }
Then you could do
Code:
// For generics (j2se 1.5+) List<PseudoStore> list = new ArrayList<PseudoStore>(); // or, for non-generics List list = new ArrayList(); list.add(new PseudoStore("John Hancock", 22)); ... String name = ((PseudoStore)list.get(0)).name; ... for(int j = 0; j < list.size(); j++) { PseudoStore store = (PseudoStore)list.get(j); System.out.println("store("+j+") = " + store); }
Reply With Quote