0

So I need to read multiple lines of text from a file in Java, for example a txt file record of peoples names height age etc.

I then need to print certain lines from the file, and certain columns, and then sort them based on tallest/oldest etc. How would I go about doing this?

I think I need to put the data from the txt file into an array? But not quite sure.

Adicode
  • 1
  • 1

1 Answers1

0

if I understood the problem, you can create a Class called Person (os something else as you wish) with all the data that you have. than read the file using a Scanner and for each line you can instantiate a new Person and add it to an ArrayList. after you finish reading all the lines from your file, you can use Collections.sort() (you can use the one with a Comparator or use the natural ordering).

links to Collections.sort Javadoc https://docs.oracle.com/javase/6/docs/api/java/util/Collections.html#sort(java.util.List) https://docs.oracle.com/javase/6/docs/api/java/util/Collections.html#sort(java.util.List,%20java.util.Comparator)