Solved

Using API

Posted on 2006-11-25
3
629 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn different types of Android Layout and some basics of an Android App.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

739 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