Win a copy of Functional Reactive Programming this week in the Other Languages forum!

# Comparing Values of multi dimensional array

ShivPrakash Srivastava
Ranch Hand
Posts: 88
Hi,

I have two multi dimensional array.I want to check each value in the array.If the values are not equal,I want to add them in another array and if they are equal,I want to skip that iteration and continue till the last element in the array.when Iam trying,iam not able to iterate through the array element.Can any pls let me know the logic for this?

Code snippet will be really helpful.

Thanks and Regards
Shiv

Ranch Hand
Posts: 209
Can you post what you have written till now? We can guide you from there on.
In general, to navigate a two-dimensional array, you need two nested loops, such as this:

For 'n' depth multi-dimensional array, you need 'n' nested loops.
Will it be better to use recursion?

ShivPrakash Srivastava
Ranch Hand
Posts: 88
Hi

Thanks for the quick response.

For example:
String[]A = {"A","B","C","D"};
String[]B = {"A","B","D"};

Now I want to iterate through array A and compare with each element in array B and want to store in another array say C,the element which are not common(in this case its "C")

Thanks and Regards
Shiv

marc weber
Sheriff
Posts: 11343
Originally posted by ShivPrakash Srivastava:
...For example:
String[]A = {"A","B","C","D"};
String[]B = {"A","B","D"};...

These are single-dimension arrays. A "multi-dimensional" array in Java is an array of arrays. For example...
String[][] multi = { {"abc", "def"}, {"ghi", "jkl", "mno"} };

marc weber
Sheriff
Posts: 11343
Your single-dimension array problem still requires a nested loop, as Shyam described above. However, instead of using the nested loop to iterate through a multi-dimensional array, you would do something like...