Reputation: 1
for example i have following code
String[] subject = new String[6];
subject[1] = JOptionPane.showInputDialog(null, "Enter subject");
String[] subject[1]=new String[6];
it will not work.There is any other way to do this?
Upvotes: 0
Views: 59
Reputation: 1406
This code also works,
String[][] subject = new String[6][];
subject[1] = JOptionPane.showInputDialog(null, "Enter subject");
subject[1]=new String[6];
altenatively, you can use the concatination operator for adding multiple strings to the value of sub array of type String,
subject[1]=subject[1]+"first"+"second"+"third";
Upvotes: 0
Reputation: 17622
You cant do that, unless you declare the first array as 2 dimensional
String[][] subject = new String[6][];
subject[1] = new String[6];
Upvotes: 3
Reputation: 1195
String[][] target = new String[VALUE_DESIRED][];
target[i] = new String[VALUE_DESIRED];
VALUE_DESIRED is a integer value which you prefer
i should less than VALUE_DESIRED
Upvotes: 0