java.util.Vector.equals() Method

Advertisements


Description

The equals(Object o) method is used to compare the specified Object with this Vector for equality. It returns true if and only if the specified Object is also a List, both Lists have the same size, and all corresponding pairs of elements in the two Lists are equal.Two Lists are defined to be equal if they contain the same elements in the same order.

Declaration

Following is the declaration for java.util.Vector.equals() method

public boolean equals(Object o)

Parameters

  • o--This is the Object to be compared for equality with this Vector.

Return Value

The method call returns true if the specified Object is equal to this Vector.

Exception

  • NA

Example

The following example shows the usage of java.util.Vector.equals() method.

package com.tutorialspoint;

import java.util.Vector;

public class VectorDemo {
   public static void main(String[] args) {
      // create two empty Vectors an initial capacity of 4      
      Vector<Integer> firstvec = new Vector<Integer>(4);
      Vector<Integer> secondvec = new Vector<Integer>(4);
      
      // additing in firstvec
      firstvec.add(4);
      firstvec.add(3);
      firstvec.add(2);
      
      // additing in secondvec
      secondvec.add(4);
      secondvec.add(3);
      secondvec.add(2);    
      
      // let us print all the elements available in vector
      System.out.println("Testing equality of firstvec and secondvec :"+ firstvec.equals(secondvec)); 
                
   } 
}

Let us compile and run the above program, this will produce the following result.

Testing equality of firstvec and secondvec :true



Advertisements
Advertisements