Solved

Using API

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java Server Faces parameter pass? 6 47
java jdbc batch example 8 29
tomcat administrtor 12 46
hibernate example using maven 12 41
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

815 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

12 Experts available now in Live!

Get 1:1 Help Now