Q:

how to read a string and then save it to an array in java

I want to read a string and then put it in the first position of a string array in java
enter code here

for (int i=1;i<100;i++) {

            System.out.print("Enter a string : ");

            Scanner scanner = new Scanner(System. in);

            String inputString = scanner.nextLine();
            System.out.println("String read from console is : \n"+inputString);
            inputString = thisIsAStringArray[];
}

A:

Reading a string should be done with while loop but what you want to do is done here. This solution saves strings to only first index.
public static void main(String [] args) {
       String [] thisIsAStringArray = new String[20]; //Only 20 string can be saved.
       Scanner in = new Scanner(System.in);
      for(int i = 0; i < 100;i++) {
        thisIsAStringArray[0] = in.nextLine(); ///Save element to first position.
        System.out.println("String entered is " + thisIsAStringArray[0]); //Get the element from the first position.
       }

}

This solution does not save to first position but to every index of the array.
public static void main(String [] args) {
        String [] thisIsAStringArray = new String[20]; //Only 20 string can be saved.
        Scanner in = new Scanner(System.in);
        for(int i = 0; i < thisIsAStringArray.length;i++) {
            thisIsAStringArray[i] = in.nextLine(); ///Save element to first position.
            System.out.println("String entered is " + thisIsAStringArray[i]); //Get the element from the first position.
        }

    }

