Click here to Skip to main content
15,920,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So I'm trying to come up with a solution that parses through two arrays and finds identical elements that are at different indexes.
Are there any ideas for a solution in Java?

What I have tried:

So one of the methods I have tried is making a boolean function and returning everything that both arrays contain.

The problem is that I can't find a way to scan all the indexes and return something that matches except on the same index.

If there are any suggestions I would be really grateful
Updated 31-Mar-22 3:39am

1 solution

You need two loops:
The outer one selects each element in the first array.
The inner one searches the second array for any value that matches the current one from the outer loop.
When you find a match, break out of the loop(s) and display the two index values.
Share this answer
CPallini 31-Mar-22 9:45am    
Richard MacCutchan 31-Mar-22 9:47am    
Daniel Robinson 2022 15-Apr-22 7:25am    
Brilliant. Thank you so much for your answer.
Richard MacCutchan 15-Apr-22 7:53am    
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900