• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic