|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
intersection of arrays
Hi,
How do I obtain the intersection of 2 arrays in Java ?? I have a String array a[] and an ArrayList ai()... Need to obtain the values in a[] which are not present in ai().. hv browsed and browsed, tried creating my own scripts but to no avail.. afaik there r no builtin function in jdk1.3 which does this.. any suggestions??? tia, gaucho |
|
#2
|
|||
|
|||
|
Hi.
I think this will solve the problem. public class test33 { public static void main( String args[] ) { int[] array1 = { 2, 4, 6, 8, 10 }; int[] array2 = { 2, 4, 5, 7, 9 }; for( int i = 0; i < array1.length; i++ ) { for( int j = 0; j < array2.length; j++ ) { if( array1[i] == array2[j] ) { System.out.println("Intersection at: " + array1[i] ); } } } } } // Output C:\>java test33 Intersection at: 2 Intersection at: 4 C:\> Hope this helps, -Caitlin. |
|
#3
|
|||
|
|||
|
hi,
thnx for the reply.. had it solved a few days bak... cheers, sands |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > intersection of arrays |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|