0
String[][] array = {{"a","b","c"},{"d","e","f"},{"g","h","i"}};
String[][] resultArray = [10][10];

i want to store first row of array values to resultArray, how can i do it in java. Please help me

2
  • String [] firstRow = array[0]; Commented Feb 4, 2014 at 11:54
  • Your resultArray is a two dimnentional array Commented Feb 4, 2014 at 11:54

3 Answers 3

1

Try with:

String[] resultArray = array[0]; //gets the first row of array
Sign up to request clarification or add additional context in comments.

2 Comments

i want to store first row of the array variable to first row of the resultArray variable, without using indexing
Well...then you will have to hardcode the value, like this: String[] resultArray = {"a", "b", "c"};
1
String[][] array = {{"a","b","c"},{"d","e","f"},{"g","h","i"}};
String[] resultArrayPtr = array[index];

if you want to copy you going to have iterate or to use clone.

2 Comments

in resultArrayPtr how can i store first row of array to first item of resultArrayPtr
@Sathesh by setting index = 0; ?
0

Try this:

copies reference

String[][] array = {{"a","b","c"},{"d","e","f"},{"g","h","i"}};
String[] resultArray = array[0];

copies values

String[][] array = {{"a","b","c"},{"d","e","f"},{"g","h","i"}};
String[] resultArray = new String[array[0].length];
System.arraycopy(array[0],0, resultArray, 0, array[0].length);

Comments

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.