java.util.Vector.hashCode() Method


Advertisements


Description

The hashCode() method is used to return the hash code value for this Vector.

Declaration

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

public int hashCode()

Parameters

NA

Return Value

The method call returns the hash code value(int) for this list.

Exception

NA

Example

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

Live Demo
package com.tutorialspoint;

import java.util.Vector;

public class VectorDemo {
   public static void main(String[] args) {

      // create an empty Vector vec with an initial capacity of 4      
      Vector<Integer> vec = new Vector<Integer>(4);

      // use add() method to add elements in the vector
      vec.add(4);
      vec.add(3);
      vec.add(2);
      vec.add(1);

      // let us get the hashcode of the vector
      System.out.println("Hash code :"+vec.hashCode());
   }
}

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

Hash code :1045631

java_util_vector.htm

Advertisements