Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 20th, 2002, 06:29 AM
sgaucho sgaucho is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2002
Posts: 26 sgaucho User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 28 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old November 24th, 2002, 02:01 PM
CaitlinG CaitlinG is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Posts: 9 CaitlinG User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Smile Intersection of two arrays.

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.

Reply With Quote
  #3  
Old November 25th, 2002, 11:16 AM
sgaucho sgaucho is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2002
Posts: 26 sgaucho User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 28 sec
Reputation Power: 0
hi,

thnx for the reply.. had it solved a few days bak...

cheers,
sands

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > intersection of arrays


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway