0

I want to add a list of 3500 Strings from a text file folder into an array. I want a solution without using an ArrayList. This is what I have so far; I am trying to sort these Strings later on using a different class:

public static void main(String[] args) throws FileNotFoundException 
{
    File fileText = new File("wordlist.txt");
    Scanner scan = new Scanner (fileText);
    
    String[] word = new String[3271];
    
    Comparator<String> com = new ComImpl();
    
    Arrays.parallelSort(words, com);

    
    for(String i: words)
    {
        System.out.println(i);
    }
}
  • 2
    *I want to add a list of 3500 Strings from a text file* - then you need to read each row of text using methods of the Scanner class. Read the API for the appropriate method to read a line of data. *I want a solution without using an ArrayList* - why? Use an ArrayList so the size can change dynamically. Hardcoding a random value for the size of the Array is a bad coding practice. – camickr Jul 01 '20 at 21:59
  • What @camickr said ^. If you want to keep an Array so you can use it in your `main` method. You could always use `Arrays.asList` to convert it to a `List`. – mohammedkhan Jul 01 '20 at 22:02

0 Answers0