File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes How to create a new array with items that are identical in two other arrays? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to create a new array with items that are identical in two other arrays?" Watch "How to create a new array with items that are identical in two other arrays?" New topic
Author

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

Marvin Diggler
Greenhorn

Joined: Aug 30, 2005
Posts: 9
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

Joined: Sep 16, 2005
Posts: 1780
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


There is no emoticon for what I am feeling!
 
jQuery in Action, 2nd edition
 
subject: How to create a new array with items that are identical in two other arrays?