Non-popping linked list

Posted on 2006-04-27
Last Modified: 2010-03-31
I wrote code that reads lines of text from a file and pushes them on a stack that is a LinkedList.

the file "test.txt" essentialy looks like this:
Abstract: . In this paper, ....
of the features drawn from the document itself.
We also present a preliminary experiment
My error is a non-terminating loop the prints to the console "bottom"  over and over.

My error must be in the following part:
while (!listit.isEmpty())
      System.out.println(; //linked_list.getFirst()
        listit.pop(); //linked_list.removeFirst()

"bottom" doesn't seem to be popping off causing the loop.

what is my errror?

Question by:kellyputty
    LVL 19

    Accepted Solution

    You forgot braces to enclose both statements in the body of the loop:

    while (!listit.isEmpty()) {
         System.out.println(; //linked_list.getFirst()
            listit.pop(); //linked_list.removeFirst()


    Author Comment

    Learning Java - O'Reilly pg92 shows while and do while w/o curly braces
    Eclipse doesn't give you a compilation  error.

    but I should have figured that out anyways considering all other expressions do and how else would it know scope.

    LVL 19

    Expert Comment

    by:Jim Cakalic
    LOL. Sometimes the obvious isn't so obvious. Good luck. BTW, you knew Java has a Stack class, right?

    Author Comment

    nope, grrr ;) now I do.  I am in the learning curve...
    LVL 30

    Expert Comment

    >> Eclipse doesn't give you a compilation  error.

    Because you can have a loop with/ without {} both. If its without {}, then only one statement is in the loop.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Suggested Solutions

    Title # Comments Views Activity
    java continue statement 10 47
    return in catch statement 1 32
    groovy example issue 10 22
    Starting to learn JAVA, 7 34
    For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
    Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
    The viewer will learn how to implement Singleton Design Pattern in Java.
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now