I need to read in a text file and then sort each strings alphabetically into array (don't need to worry about case sensitivity).
I need to use the arrays to to do binary search later.
Here is the code:
public class project2 {
public static void main( String[] args ) throws IOException {
String[] list = { "" };
list = load_list( "wordlist.txt" );
ArrayList<String> words =new ArrayList<String>(Arrays.asList(list));
File fileReader = new File( "wordlist.txt" );
Scanner inputFile = new Scanner( fileReader );
Collections.sort(words,String.CASE_INSENSITIVE_ORDER);
}
public static String[] load_list( String wordlist ) throws IOException {
File fileReader = new File( "wordlist.txt" );
Scanner inputFile = new Scanner( fileReader );
List<String> L = new ArrayList<String>();
while ( inputFile.hasNextLine() ) {
L.add(inputFile.nextLine());
}
return L.toArray(new String[L.size()]);
}
}
The first block of code is my attempt to read and sort them
the 2nd block is to read each line of strings
Im ahead of myself but can someone give me hint on using the result of these codes to do sequential/binary search?
String[]return type at method signature, but didn't return anything.