Thursday, July 4, 2024
HomeLanguagesJavaChoiceFormat hashCode() method in Java with Examples

ChoiceFormat hashCode() method in Java with Examples

The hashCode() method of java.text.ChoiceFormat class is used to get the hash code for choice format object. This hashcode value is returned as an integer.

Syntax:

public int hashCode()

Parameter: This method does not accept any parameter.

Return Value: This method returns hash code for choice format object as an integer.

Below are the examples to illustrate the hashCode() method:

Example 1:




// Java program to demonstrate hashCode() method
  
import java.text.*;
import java.util.*;
import java.io.*;
  
public class GFG {
    public static void main(String[] argv)
    {
        // creating and initializing ChoiceFormat
        ChoiceFormat cf
            = new ChoiceFormat(
                "4#wed| 5#thu | 6#fri | 7#sat");
  
        // getting hashcode of  ChoiceFormat object
        // using hashCode() method
        int hash = cf.hashCode();
  
        // display the result
        System.out.print("hashCode :- " + hash);
    }
}


Output:

hashCode :- 113634 

Example 2:




// Java program to demonstrate hashCode() method
  
import java.text.*;
import java.util.*;
import java.io.*;
  
public class GFG {
    public static void main(String[] argv)
    {
        // creating and initializing limit
        double[] limit = { 1, 2, 3, 4 };
  
        // creating and initializing format
        String[] format
            = { "add", "sub", "multiply", "divide" };
  
        // creating and initializing ChoiceFormat
        ChoiceFormat cf
            = new ChoiceFormat(limit, format);
  
        // getting hashcode of  ChoiceFormat object
        // using hashCode() method
        int hash = cf.hashCode();
  
        // display the result
        System.out.print("hashCode :- " + hash);
    }
}


Output:

hashCode :- -1331463043

Reference: https://docs.oracle.com/javase/9/docs/api/java/text/ChoiceFormat.html#hashCode–

Nokonwaba Nkukhwana
Experience as a skilled Java developer and proven expertise in using tools and technical developments to drive improvements throughout a entire software development life cycle. I have extensive industry and full life cycle experience in a java based environment, along with exceptional analytical, design and problem solving capabilities combined with excellent communication skills and ability to work alongside teams to define and refine new functionality. Currently working in springboot projects(microservices). Considering the fact that change is good, I am always keen to new challenges and growth to sharpen my skills.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments