Question: This task requires and array of 26 indexes. Each array index needs to hold an array list containing strings. For example when I read in

This task requires and array of 26 indexes. Each array index needs to hold an array list containing strings. For example when I read in a file I will be able to put all the words that start with character a in the arrayList held in index 0 of the array words that start with character b will go into the arrayList held at index 1 and so on all the way to z. Some of the commented lines ar just where I have been trying different approaches. Thanks for any help!

package mylinkedlist;

import java.io.*; import java.util.*; public class MyLinkedList {

public static void main(String[] args) throws Exception{ MyLinkedList[] list = new MyLinkedList[25]; for (int i = 0; i < list.length; i ++) { list[i] = new ArrayList<>(); } //String[] array = new String[26]; //List list = new ArrayList<>(); try { // Open the file that is the first // command line parameter FileInputStream fstream = new FileInputStream("random_dictionary.txt"); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; while ((strLine = br.readLine()) != null) { // Print the content on the console //char c = strLine.charAt(0); //int k = (int) c; //for ( int i =97; i < 123; i ++){ // if (k == i) { // array[i-97] += strLine + " " ; // adds word to array index alphabetically //} list.add(strLine); in.close(); //Close the input stream } } catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); } // end catch Collections.sort(list,String.CASE_INSENSITIVE_ORDER); System.out.println(list); //for(int i = 0; i < array.length; i ++) { // System.out.println(array[i] +" "); //}

} }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!