Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to create a new array with items that are identical in two other arrays?

 
Marvin Diggler
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have two arrays that contain integers. I want to create a new array with only integers that exist in two other arrays. Is there a simple way to do this? I can either create a new array or erase items from one of the arrays if it does not exist in the other.
Thanks!
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic