The Wayback Machine - https://web.archive.org/web/20240618020216/https://www.geeksforgeeks.org/vector-hashcode-method-in-java/
Open In App

Vector hashCode() Method in Java

Last Updated : 17 Aug, 2018
Improve
Improve
Like Article
Like
Save
Share
Report

The java.util.vector.hashCode() method in Java is used to get the hashcode value of this vector.

Syntax:

Vector.hashCode()

Parameters: The method does not take any parameter.

Return Value: The method returns hash code value of this Vector which is of Integer type.

Below programs illustrate the Java.util.Vector.hashCode() method:

Program 1: Vector with string elements.




// Java code to illustrate hashCode()
import java.util.*;
  
public class VectorDemo {
    public static void main(String args[])
    {
        // Creating an empty Vector
        Vector<String> vec_tor = new Vector<String>();
  
        // Use add() method to add elements into the Vector
        vec_tor.add("Welcome");
        vec_tor.add("To");
        vec_tor.add("Geeks");
        vec_tor.add("4");
        vec_tor.add("Geeks");
  
        // Displaying the Vector
        System.out.println("Vector: " + vec_tor);
  
        // Displaying the hashCode value of Vector
        System.out.println("The hashCode value is: "
                           + vec_tor.hashCode());
    }
}


Output:

Vector: [Welcome, To, Geeks, 4, Geeks]
The hashCode value is: -878886256

Program 2: Vector with integer elements.




// Java code to illustrate hashCode()
import java.util.*;
  
public class VectorDemo {
    public static void main(String args[])
    {
        // Creating an empty Vector
        Vector<Integer> vec_tor = new Vector<Integer>();
  
        // Use add() method to add elements into the Vector
        vec_tor.add(10);
        vec_tor.add(20);
        vec_tor.add(30);
        vec_tor.add(40);
        vec_tor.add(50);
  
        // Displaying the Vector
        System.out.println("Vector: " + vec_tor);
  
        // Displaying the hashCode value of Vector
        System.out.println("The hashCode value is: "
                           + vec_tor.hashCode());
    }
}


Output:

Vector: [10, 20, 30, 40, 50]
The hashCode value is: 38490301


Previous Article
Next Article

Similar Reads

Method Class | hashCode() Method in Java
The java.lang.reflect.Method.hashCode() method returns the hash code for the Method class object. The hashcode returned is computed by exclusive-or operation on the hashcodes for the method's declaring class name and the method's name. The hashcode is always the same if the object doesn't change. Hashcode is a unique code generated by the JVM at ti
4 min read
Copy Elements of One Java Vector to Another Vector in Java
Vector is similar to arrays but is growable also, or we can say no fixed size is required. Previously vector was a part of legacy classes but now it is part of Collections. It also implements a List interface, so we can use any method of list interface on vectors also. Syntax : Vector&lt;Integer&gt; gfg=new Vector&lt;&gt;(); Ways To copy elements o
3 min read
Integer hashCode() Method in Java
The java.lang.Integer.hashCode() method of Integer class in Java is used to return the hash code for a particular Integer . Syntax: public int hashCode() Parameters : The method does not take any parameters. Return Value: The method returns a hash code integer value for this object, which is equal to the uncomplicated primitive integer value, repre
2 min read
BigDecimal hashCode() Method in Java
The java.math.BigDecimal.hashCode() returns the hash code for this BigDecimal. The hashcode will generally not be the same for two BigDecimal objects with equal values and different scale (like 4743.0 and 4743.00). Syntax: public int hashCode() Parameters: This method does not accept any parameters. Return Values: This method returns an integer val
2 min read
IdentityHashMap hashCode() Method in Java
The java.util.IdentityHashMap.hashCode() method in Java is used to fetch the hash code value of a particular this IdentityHashMap. A map consists of a number of buckets to store the key-value pair. Each bucket has a unique identity and when a key-value pair is inserted into a bucket, the key's hashcode is matched with the identifier of the bucket,
2 min read
GregorianCalendar hashCode() Method in Java
The java.util.GregorianCalendar.hashCode() is an in-built function in Java which generates hash code for this GregorianCalendar instance. Syntax: public int hashCode() Parameters: This function does not accept any parameters. Return Values: This function returns an integer value which represents the hash code for this GregorianCalendar instance. Ex
2 min read
BigInteger hashCode() Method in Java
The java.math.BigInteger.hashCode() method returns the hash code for this BigInteger. The hashcode is always the same if the object doesn't change. Hashcode is a unique code generated by the JVM at the time of object creation. We can use hashcode to perform some operation on hashing related algorithms like hashtable, hashmap etc. We can search an o
2 min read
Java 8 Clock hashCode() method with Examples
Java Clock class is part of Date Time API, java.time.Clock, of Java. The Java Date Time API was added from Java version 8. hashCode() method of Clock class returns the hash code for this Clock Object. Clocks object overrides this method based on their state. If clock object is not overridden, the behavior of this method is defined by Object.hashCod
2 min read
CopyOnWriteArrayList hashCode() method in Java
The hashCode() method of CopyOnWriteArrayList returns the hashCode value of the list. Syntax: public int hashCode() Parameters: The function does not accepts any parameter. Return Value: The function returns the hashCode value of the list. Below programs illustrate the above function: Program 1: // Java Program to illustrate the CopyOnWriteArrayLis
1 min read
Boolean hashCode() method in Java with examples
The hashCode() method of Boolean class is a built in method to return a int hashcode value corresponding to the Boolean object. Syntax BooleanObject.hashCode() Return Type: It returns a int hashcode value corresponding to the Boolean object. It returns 1231 if the Boolean object stores the value true. It returns 1237 if the Boolean object stores th
1 min read