Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7600901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:01:50+00:00 2026-05-30T23:01:50+00:00

So basically I have a Linked List class that has all of the constructor

  • 0

So basically I have a Linked List class that has all of the constructor data necessary to read a file I have and then convert it into a Linked List. However when it reads in the file data it is adding lines and spaces incorrectly. I am using system.out.println to check and it is coming out incorrectly. I don’t think it is the toString method because I have messed with it so much and nothing changes. I need help with this because I cant figure it out.
Thanks!

File Information(Basically All of the data is on separate lines):

tobi
tobi
tobi@hotmail.com
tobi
Mixed Breed
Male
3-4
Virginia
Walking
lily
lily
lily@hotmail.com
lily
Yorkshire Terrier
Female
3-4
Hawaii
Jumping
peppy
peppy
peppy@hotmail.com
peppy
Chihuahua
Male
7-8
Alaska
Sleeping
fluffy
fluffy
fluffy@hotmail.com
fluffy
MixedBreed
Female
3-4
Virginia
Walking 
flower
flower
flower@hotmail.com
flower
Chihuahua
Female
7-8
Alaska
Sleeping

Linked List:

    import java.io.Serializable;
    import java.util.*;

    public class LinkedAccountList implements Serializable{

    private String username;
    private String password;
    private String email;
    private String name;
    private String breed;
    private String gender;
    private String age;
    private String state;
    private String hobby;

    public LinkedAccountList (String username, String password, String email, String name, String breed, String gender, String age, String state, String hobby){
    this.username = username;
    this.password = password;
    this.email = email;
    this.name = name;
    this.breed = breed;
    this.gender = gender;
    this.age = age;
    this.state = state;
    this.hobby = hobby;
    }

    public String getUsername(){
    return username;
    }

    public String getPassword(){
    return password;
    }

    public String getEmail(){
    return email;
    }

    public String getName(){
    return name;
    }

    public String getBreed(){
    return breed;
    }

    public String getGender(){
    return gender;
    }

    public String getAge(){
    return age;
    }

    public String getState(){
    return state;
    }

    public String getHobby(){
    return hobby;
    }

    @Override
    public String toString() {
    return "Username: "+username+"\nPassword: "+password+"\nEmail: "+email+"\nName: "+name+"\nBreed: "+breed+"\nGender: "+gender+"\nAge: "+age+"\nState: "+state+"\nHobby: "+hobby;
    }

    public void setUsername(String u){
    username = u;
    }

    public void setPassword(String p){
    password = p;
    }

    public void setEmail(String e){
    email = e;
    }

    public void setName(String n){
    name = n;
    }

    public void setBreed(String b){
    breed = b;
    }

    public void setGender(String g){
    gender = g;
    }

    public void setAge(String a){
    age = a;
    }

    public void setState(String s){
    state = s;
    }

    public void setHobby(String h){
    hobby = h;
    }

    }

Read from File and create Linked List Method:

    LinkedList<LinkedAccountList> account = new LinkedList<LinkedAccountList>();

    try
    {
    read(account, "file.txt");
    } catch (Exception e)
    {
    System.err.println(e.toString());
    }
    display(account);
    }

    public static void read(LinkedList<LinkedAccountList> account, String inputFileName) throws java.io.IOException
    {
    BufferedReader infile = new BufferedReader(new FileReader(inputFileName));
    while(infile.ready())
    {
    String username = infile.readLine();
    String password = infile.readLine();
    String email = infile.readLine();
    String name = infile.readLine();
    String breed = infile.readLine();
    String gender = infile.readLine();
    String age = infile.readLine();
    String state = infile.readLine();
    String hobby = infile.readLine();

    LinkedAccountList d = new LinkedAccountList(username, password, email, name, breed, gender, age, state, hobby);
    account.add(d);
    }
    infile.close();
    }

Here is what the output looks like(Look closely and you can see the problem):

Username: tobi
Password: tobi
Email: tobi@hotmail.com
Name: tobi
Breed: Mixed Breed
Gender: Male
Age: 3-4
State: Virginia
Hobby: Walking
Username: 
Password: lily
Email: lily
Name: lily@hotmail.com
Breed: lily
Gender: Yorkshire Terrier
Age: Female
State: 3-4
Hobby: Hawaii
Username: Jumping
Password:  peppy
Email: peppy
Name: peppy@hotmail.com
Breed: peppy
Gender: Chihuahua
Age: Male
State: 7-8
Hobby: Alaska
Username: Sleeping
Password: fluffy
Email: fluffy
Name: fluffy@hotmail.com
Breed: fluffy
Gender: Mixed Breed
Age: Female
State: 3-4
Hobby: Virginia
Username: Walking 
Password: flower
Email: flower
Name: flower@hotmail.com
Breed: flower
Gender: Chihuahua
Age: Female
State: 7-8
Hobby: Alaska
Username: Sleeping
Password: null
Email: null
Name: null
Breed: null
Gender: null
Age: null
State: null
Hobby: null
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T23:01:51+00:00Added an answer on May 30, 2026 at 11:01 pm

    You don’t have any validation, any logging.
    You should at least create method:

    public String readLine(BufferedReader br){
        String rl = br.readLine();
        if (rl.trim().length() > 2) {
            return rl;
        }else return readLine(br);
    }
    

    and use it like:

    ...
         while(infile.ready())
            {
              String username = readLine(infile); // instead of String username = infile.readLine();
    

    Also using so long constructor argument is error-prone

    LinkedAccountList (String username, String password, String email,
    String name, String breed, String gender, String age, String state,
    String hobby){

    Use ony setX(String arg) method. This is common practise in DAO pattern.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, I have a Linked List which implements a display() function that simply loops
I currently have multiple queries that query data from a few tables linked through
Is there a pre-implemented linked list out there that would have been implemented using
So basically I have this constructor for the class League : import java.util.*; public
I have a table that looks basically like this: id | redirectid | data
I basically have a page which shows a processing screen which has been flushed
I basically have 7 select statements that I need to have the results output
my model is basically a chain of objects linked by a foreign key: class
I need to have a UserProfile class that it's just that, a user profile.
I have a problem either adding to or traversing a linked list. The main

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.