Hello, i'm new to java and i need to read a file of strings into an array and then sort them but i can't figure out how to do either. i can do it with ints and doubles but i can't with strings. if anyone could help me i'd be very gratful
import java.io.*;
import java.util.*;
public class SortStringsFromFile
{
public static void main(String[] args)throws IOException
{
// O = Orginal
// S = Sorted
String[] Ostring = new String[100];
String[] Sstring = new String[100];
int sizeN = ReadFile(Ostring, Sstring);
Sorter(Sstring);
PrintResults(sizeN, Ostring, Sstring);
}
public static int ReadFile( String[] Ostring, String[] Sstring)throws IOException
{
Scanner fileScan = new Scanner(new File( "String.txt"));
int count = 0;
while( fileScan.hasNext())
{
String word = " ";
Ostring[count] = word;
Sstring[count] = word;
count++;
}
fileScan.close();
return count;
}
public static void Sorter(String[] Sstring)throws IOException
{
java.util.Arrays.sort(Sstring[]);
}
public static void PrintResults( int sizeN, String[] Ostring, String[] Sstring)throws IOException
{
int i = 0;
System.out.println("Orginal List");
while(i < sizeN)
{
System.out.println(Ostring[i]);
i++;
}
System.out.println(" ");
i = 0;
System.out.println("Sorted List");
while(i < sizeN)
{
System.out.println(Sstring[i]);
i++;
}
}