Results 1 to 2 of 2
Thread: Storing Data
- 08-02-2007, 04:26 AM #1
Member
- Join Date
- Aug 2007
- Posts
- 1
- Rep Power
- 0
Storing Data
Goodday everyone,
About 3 weeks ago i have started picking up java, and trying to grasp the basics i decided to try and put together a simple yet challenging program.
the program basicly needs to store multiple names and a value that goes with each name to a file, after which i want to be able to edit and change the value.
Now my question is what would be the best way to realise this (keep in mind i might want to display the entire list in a GUI) i was thinking of having an array go through the file each time you want to change a value by searching for the name that the user inputs, however this seems rather difficult in terms of flexibility, i also noticed the Linkedlist in the API, at first glance however it seems this only stores 1 variable (be it string or int) and not 2?
Could someone give me a push in the right direction?
Thanks in advance, Khorod.
- 08-03-2007, 05:48 AM #2
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:
Java 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 + "]"; } }
Java 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); }
Similar Threads
-
[SOLVED] Why import isnt needed whn ref is used without storing to local variable
By N_i_X in forum Advanced JavaReplies: 2Last Post: 03-31-2008, 05:11 AM -
storing and retrieving a file as such
By anil_manu in forum Advanced JavaReplies: 0Last Post: 03-11-2008, 01:27 PM -
Storing data permanently
By shaungoater in forum New To JavaReplies: 2Last Post: 03-10-2008, 04:18 PM -
Reading form inputStream and storing in ByteArray
By Java Tip in forum Java TipReplies: 0Last Post: 11-27-2007, 10:23 AM -
Problem with storing and retrieving from a textfile
By Albert in forum Advanced JavaReplies: 1Last Post: 07-13-2007, 03:01 PM
Bookmarks