how can i store string arrays in a LinkedList

D

David

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

Andy Fish

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
 
M

Manish Jethani

David said:
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
 
J

Jonathan Oexner

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. ;)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top