Another quick question. I have a text file with lines consisting of one integer, and four strings. Currently, I am able to search through this file and find any of the variables listed within. However, if any of the variables are listed more than once, and I search for that particular varable name, it only prints out the first line containing that particular variable name.
Basically, how do I modify the following code so that the search method returns all the instances of a particular variable name in the text file?
You said you wanted to return more than one Title. What's a nother word for "more than one" ... maybe a "collection" of Titles? You can return an array or List or whatever suits the task. Title is nice because it specifies the type better than List, but it's hard to create an array of the right size before you're done searching. In Java5 you can return List<Title>.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
posted 13 years ago
Many thanks for the reply.
I have tried implementing the lookUpDirector method as follows,
When I use this method with the previous test main class, it compiles and runs, but after the user inputs the name of the director to search for, the input window freezes indefinitely and no result is achieved. The output pane in NetBeans is as follows,
The only way to stop the process is to terminate it in the Runtime section of NetBeans.
Your "next" variable, which you are using as an index, is only being incremented when it matches.... so... on you first mismatch, you will go into an endless loop checking the same title over and over again.
Thanks for the reply. I now see what you mean. If I enter the name of the director in the first line of the text file, it returns the correct details. Any search pas this line and the previous problem starts.
The text file being searched has many lines, each with one integer and four strings. Some lines may have the same string details.
With regard to my earlier code, however, how do I break it out of the continuous loop?
posted 13 years ago
Thanks for your help. It's all solved now.
I had been staring at it for too long, and couldn't see the wood for the trees. I have now moved the next statement outside the braces within the method, and it now returns the correct information from the file.