The Artima Developer Community
Sponsored Link

Java Answers Forum
I/O file reading into a singly LinkedList Need Help

1 reply on 1 page. Most recent reply: Apr 14, 2002 10:28 PM by Matt Gerrans

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Jackie

Posts: 4
Nickname: jackie
Registered: Apr, 2002

I/O file reading into a singly LinkedList Need Help Posted: Apr 14, 2002 8:48 PM
Reply to this message Reply
Advertisement
Hi there,

Can anyone please help me! I get lost when I'm reading from input file into a singly linkedlist. I'm not quite sure if im reading it correctly. Also, I don't know how to display all informations in my list.

(SOME CODE FOR MY INFILE)
// Reads the file
while( (line = inFile.readLine()) != null )
{
attName = line;
attId = new Integer(inFile.readLine ().trim)).intValue();
attAddress = inFile.readLine();

// Create an object to store the attendee details
attendee = new AttendeesInfo
(attName,attId,attAddress);

//insert each attendee into the list.
list.insertToFront(attendee);
} // while

How do I display the items in my list. For instance in each node in my list it consist of 3 different data (ie String, int, String).
Please help!!!!


Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: I/O file reading into a singly LinkedList Need Help Posted: Apr 14, 2002 10:28 PM
Reply to this message Reply
Here is a previous answer to reading lines from a file into a List:
http://www.artima.com/forums/flat.jsp?forum=1&thread=791

You are calling insertToFront(), which is not a part of List or any of its API implementations, so I guess you are using your own linked list. That means there is no way for we in this forum to know how you get elements from that list. If I were you, I'd switch to using the List interface that comes with the Java API along with an ArrayList or LinkedList. Then, printing out the list will be a simple matter of doing a System.out.println(list); or, if you want to do some more fancy stuff, getting an Iterator from the list and printing out the elements to your liking.

By the way, your AttendeesInfo class should define toString(), so that when the List tries to render each element for printing, it gets something nice to look at, not the default Object implementation of toString().

Flat View: This topic has 1 reply on 1 page
Topic: Linkedlist? Previous Topic   Next Topic Topic: reading a file from jsp ???

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use