aspose 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
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to create a new array with items that are identical in two other arrays?
 
Similar Threads
arrays are like strings which are objects!
Array Definition Question
find duplicates
Why cant we declare the size of Array in java?
Some questions for newcomer as ME.Pls help ME.