I'm confused about a simple question. Can you tell me how to define a string array without length? Because I can't find any information about this question. if I write String[] str=new String[];
or String[] str=new String[]{};
they will have error. But why?
Thx!!!
Here is my homework: write a program to read a series of words from the command-line arguments, and find the index of the first match of a given word. For example,java First Match lady That young lady looks after the old lady. would find the index for the first match of “lady” in the sentence “That young lady looks after the old lady”, and display the index of its first occurrence in the sentence on console, e.g.,“The index of the first match of ‘lady’is 2”.
Here is my code:
String[] str=new String[11];
int a=0;
for(int i=0;i<11;i++){
str[i] = args[a];
a++;
}