Results 1 to 2 of 2

Thread: Storing Data

  1. #1
    Khorod is offline Member
    Join Date
    Aug 2007
    Posts
    1
    Rep Power
    0

    Default 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.

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    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 + "]";
        }
    }
    Then you could do
    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

  1. Replies: 2
    Last Post: 03-31-2008, 06:11 AM
  2. storing and retrieving a file as such
    By anil_manu in forum Advanced Java
    Replies: 0
    Last Post: 03-11-2008, 02:27 PM
  3. Storing data permanently
    By shaungoater in forum New To Java
    Replies: 2
    Last Post: 03-10-2008, 05:18 PM
  4. Replies: 0
    Last Post: 11-27-2007, 11:23 AM
  5. Problem with storing and retrieving from a textfile
    By Albert in forum Advanced Java
    Replies: 1
    Last Post: 07-13-2007, 04:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •