I wanted to practice with array and I don't get why it doesn't print the following out: The problem is that the terminal outputs: null Why is that and what did I do wrong?
package Practice;
public class CreatingArrays {
public static void main(String[] args) {
String[] women = { "persian", "palestinian", "german", "russian", "spanish", "italian", "greek", "hungarian",
"brazilian", "turkish" };
women = new String[10];
System.out.println(women[8]);
}
}
CodePudding user response:
You are re-assigning women to be an empty string[10] before printing to console.
Remove women = new String[10];
and it should work fine.
CodePudding user response:
String[] women = { "persian", "palestinian", "german", "russian",
"spanish", "italian", "greek", "hungarian","brazilian", "turkish" };
System.out.println(women[8]);
Will work for you.