Solved

Using API

Posted on 2006-11-25
3
616 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

920 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

13 Experts available now in Live!

Get 1:1 Help Now