I need to take an array of three lines in a text file and sort them base on the first line in Java.

Posted by Cory on Stack Overflow See other posts from Stack Overflow or by Cory
Published on 2010-05-03T00:37:28Z Indexed on 2010/05/03 0:48 UTC
Read the original article Hit count: 714

Filed under:
|

I need to take an array of three lines in a text file and sort them base on the first line in Java. I also need to manipulate this as well and then print to screen.

I have a test file that is formatted like this:

10
Michael
Jackson
12
Richard
Woolsey

I need to input this from a text file and then rearrange it based on the number associated with the name. At that point, I need to use a random number generator and assign a variable based on the random number to each name. Then I need to print to screen the variable I added and the name in a different format. Here is an example of the output:

12:
Woolsey, Richard
Variable assigned
10:
Jackson, Michael
Other variable assigned

I highly appreciate any help. I ask because I do not really know how to input the three lines as one variable and then manipulate later on in the program. Thanks, Cory

© Stack Overflow or respective owner

Related posts about java

Related posts about arrays