wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Comparing Values of multi dimensional array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Comparing Values of multi dimensional array" Watch "Comparing Values of multi dimensional array" New topic
Author

Comparing Values of multi dimensional array

ShivPrakash Srivastava
Ranch Hand

Joined: Mar 24, 2005
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
Shyam Prasad Murarka
Ranch Hand

Joined: May 02, 2005
Posts: 209
Dear Reader,
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?


With Best Regards,
Shyam Prasad Murarka
ShivPrakash Srivastava
Ranch Hand

Joined: Mar 24, 2005
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

Joined: Aug 31, 2004
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"} };


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
marc weber
Sheriff

Joined: Aug 31, 2004
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...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Comparing Values of multi dimensional array
 
Similar Threads
Doubt in Arrays
2d arrays and form bean
about hashmap implementation of arraylist
tutorial of 2-dimensional arrays
Multi-dimensional properties file