This week's book giveaway is in the Agile and Other Processes forum. We're giving away four copies of Darcy DeClute's Scrum Master Certification Guide: The Definitive Resource for Passing the CSM and PSM Exams and have Darcy DeClute on-line! See this thread for details.
Please use real words when posting to the forums. Abbreviations such as "pliz" in place of "please" only serve to make your posts more difficult to read and less likely to generate useful responses.
You can't randomly read a line from a file (unless each line in the file is of the same length, then you can use a RandomAccesFile), you need to read every line sequentially.
So you could read each line of the file into an ArrayList. Then when you generated the random number you access the line from the ArrayList.
Bear Bibeault wrote:Sure. You could use an array. But that would likely be wasteful and inefficient and prone to error unless you know in advance how many lines to read.
What's your beef with ArrayLists?
its not that i have beef with ArrayLists, i cant learn them now.. will try to use the LineNumberReader. how is it
You can only read a specific line without using a List if you already know how many lines there are. If you don't you may end up trying to read a line that simply isn't there.
As for how List and ArrayList work, it's really simple. In pseudo code:
For more information, read this.