Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > how can i store string arrays in a LinkedList

Reply
Thread Tools

how can i store string arrays in a LinkedList

 
 
David
Guest
Posts: n/a
 
      07-30-2003
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


 
Reply With Quote
 
 
 
 
Andy Fish
Guest
Posts: n/a
 
      07-30-2003
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
 
Manish Jethani
Guest
Posts: n/a
 
      07-30-2003
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

 
Reply With Quote
 
David
Guest
Posts: n/a
 
      07-30-2003
to achieve add, delete and search, is LinkedList the best choise?


 
Reply With Quote
 
Jonathan Oexner
Guest
Posts: n/a
 
      07-31-2003
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multidimensional arrays and arrays of arrays Philipp Java 21 01-20-2009 08:33 AM
How to synchronize access to LinkedList?? Tobi Krausl Java 2 11-06-2003 04:52 PM
LinkedList? Knute Johnson Java 3 10-27-2003 06:41 PM
LinkedList NullPointerException occurs after switched from IBM JVM 1.4.0 to 1.4.1 Tohru Kao Java 3 07-14-2003 08:12 AM
LinkedList NullPointerException occurs after switched from IBM JVM 1.4.0 to 1.4.1 Tohru Kao Java 1 07-08-2003 09:09 AM



Advertisments