Yasir pp
Yasir pp

Reputation: 1

How can an element of a string array be used as a variable of another string array in java?

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

Answers (3)

Balayesu Chilakalapudi
Balayesu Chilakalapudi

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

sanbhat
sanbhat

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

Krishna M
Krishna M

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

Related Questions