It sounds like you want to find the intersection of two sets, right?
You could do that easily enough with java.util.Set<Integer>. Most of the fiddling
would involve converting this set back to a int[]. Do you have to work
with arrays?
BTW, do you know how to use the collection framework:
http://java.sun.com/docs/books/tutorial/collections/index.html