0

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?

3 Answers 3

3

You cant do that, unless you declare the first array as 2 dimensional

String[][] subject = new String[6][];

subject[1] = new String[6];
Sign up to request clarification or add additional context in comments.

2 Comments

it is not the case.actually I want to create a new array, whose variable name is the element of subject array
You cant do that , thats the answer :)
0
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

Comments

0

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";

2 Comments

String[] subject={"java","php","C#","C++"}; now i want to crate arrays like String[] java; String[] php;.. if these elements (java,php,c++)enterd in run time. how it is used as a variable to create a new array
use the concatination operator(+).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.