Search code examples
javafilesortingtext

Sorting a text file in Java


I have a text file with a list of words which I need to sort in alphabetical order using Java. The words are located on seperate lines.

How would I go about this, Read them into an array list and then sort that??


Solution

  • This is a simple four step process, with three of the four steps addressed by Stackoverflow Questions:

    1. Read each line and turn them into Java String
    2. Store each Java String in a Array (don't think you need a reference for this one.)
    3. Sort your Array
    4. Write out each Java String in your array