Solved

Using API

Posted on 2006-11-25
3
614 Views
Last Modified: 2012-06-22
ok so i found a method on that site which is  

java.util.Vector intersection(java.util.Vector v1, java.util.Vector v2, boolean sorted)
          Returns the intersection of two vector.

on this website
http://joggplayer.webarts.bc.ca/html/docs/api/kiwi/util/VectorUtils.html

how do i call the intersection function... i keep getting undefined...what do i have to do?
0
Comment
Question by:Squadless
  • 2
3 Comments
 
LVL 14

Assisted Solution

by:sudhakar_koundinya
sudhakar_koundinya earned 400 total points
ID: 18013352
Hi there

the documentation what you have seen is developed by some other person and is not a part of sun API.

This simple solution will help you to get the intersection of two lists

public static java.util.Vector intersection  (java.util.Vector a,  java.util.Vector b)
      {
            java.util.HashSet c= new java.util.HashSet();
            for(int i=0;i<a.size();i+=1)
            {
                  for(int j=0;j<b.size();j++)
                  {      
                        if(a.elementAt(i).equals(b.elementAt(j)))
                        {
                              c.add(a.elementAt(i));
                        }
                  }
            }
            return new java.util.Vector(c);

      
      
      }


calling the above code,,,,
               java.util.Vector a=new java.util.Vector();
            a.add(1);a.add(3);a.add(2);

            java.util.Vector b=new java.util.Vector();
            b.add(3);b.add(4);b.add(2);
            java.util.Vector c=      intersection(a,b) ;
            System.err.println(c);
0
 
LVL 14

Accepted Solution

by:
hoomanv earned 100 total points
ID: 18013541
Or use Apache Commons Collections, which have methods for intersection, union, etc
http://jakarta.apache.org/commons/collections/api-release/index.html
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 18013557
Your API is just the same

VectorUtils util = new VectorUtils();
Vector intersection = util.intersection(v1, v2, false); // or true in case the vectors are sorted
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now