how can i store string arrays in a LinkedList

Discussion in 'Java' started by David, Jul 30, 2003.

  1. David

    David Guest

    String [] stu_info=new String[5]
    stu_info[0]=stu_id
    stu_info[1]=stu_fname
    stu_info[2]=stu_lname
    stu_info[3]=assignment
    stu_info[4]=asign_content

    can i put this array into a LinkedList, so that i can manipulate these
    record efficiently.

    --
    Bi Hongliang / David
    David, Jul 30, 2003
    #1
    1. Advertising

  2. David

    Andy Fish Guest

    firstly I think you want to put the strings themselves into a list rather
    than arrays of strings

    I'm not sure why you think you need a linked list. Java provides plenty of
    built in types - ArrayList is usually the most convenient and won't be a
    performance problem unless you have a really performance critical app or
    thousands of entries. otherwise you could try Hashtable. Just look at the
    API documentation and choose the most effective data structure for your
    application

    Andy

    "David" <> wrote in message
    news:...
    > String [] stu_info=new String[5]
    > stu_info[0]=stu_id
    > stu_info[1]=stu_fname
    > stu_info[2]=stu_lname
    > stu_info[3]=assignment
    > stu_info[4]=asign_content
    >
    > can i put this array into a LinkedList, so that i can manipulate these
    > record efficiently.
    >
    > --
    > Bi Hongliang / David
    >
    >
    Andy Fish, Jul 30, 2003
    #2
    1. Advertising

  3. David wrote:

    > String [] stu_info=new String[5]
    > stu_info[0]=stu_id
    > stu_info[1]=stu_fname
    > stu_info[2]=stu_lname
    > stu_info[3]=assignment
    > stu_info[4]=asign_content
    >
    > can i put this array into a LinkedList, so that i can manipulate these
    > record efficiently.


    Yes, you can put this array into a LinkedList.

    However, you should probably create an data object to store the
    record, instead of using a String[]

    class StudentInfo {
    String id;
    String fname;
    String lname;
    String assignment;
    String assignContent;
    }

    Add getXXX() and setXXX() methods for each of the fields, and
    use the appropriate Java type for each (id might be an int, for
    example).

    Manish

    --
    Manish Jethani (manish.j at gmx.net)
    phone (work) +91-80-51073488
    Manish Jethani, Jul 30, 2003
    #3
  4. David

    David Guest

    to achieve add, delete and search, is LinkedList the best choise?
    David, Jul 30, 2003
    #4
  5. Well, to be really OO about it, you'd probably want to use some
    wrapper that will abstract you away from all the hairiness that's
    inherent in your requirements. What you really need is a good ol'
    relational database, but you can mock one up yourself in a pinch.
    Start off with something like the StudentInfo class suggested above.
    Then whip up a wrapper class with methods like addStudent,
    removeStudent, and all the getStudentsBy<whatever> attributes you need
    to search by. For each attribute, maintain a Map, where the keys are
    the value you're searching for and the values are Sets of Students
    that fit that query. You'd just have to maintain those Maps on
    inserts by pulling the Set of Students that match the query if it
    exists (and creating it if it doesn't) and adding the new Student to
    it (and placing the new Set into the Map if you just created one).
    Conversely, deletes would do gets on all the attributes, find the ones
    that match all the criteria, and removing them from the Sets in the
    Maps (and wiping out any Sets you may happen to empty along the way).

    ....and if you need to search by more than one attribute, then, well,
    get a database. ;)
    Jonathan Oexner, Jul 31, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tohru Kao
    Replies:
    3
    Views:
    432
    Neil Masson
    Jul 14, 2003
  2. Tohru Kao
    Replies:
    1
    Views:
    390
    Chris
    Jul 8, 2003
  3. Knute Johnson

    LinkedList?

    Knute Johnson, Oct 26, 2003, in forum: Java
    Replies:
    3
    Views:
    5,864
    Knute Johnson
    Oct 27, 2003
  4. Tobi Krausl
    Replies:
    2
    Views:
    13,651
    Michael Borgwardt
    Nov 6, 2003
  5. Philipp
    Replies:
    21
    Views:
    1,127
    Philipp
    Jan 20, 2009
Loading...

Share This Page