Java Locale hashCode() Example

Locale class hashCode() method example. This example shows you how to use hashCode() method.


Syntax is : public int hashCode()
Method returns hashCode. Since Locales are often used in hashtables, caches the value for speed.

Here is the code.

/**
 * @(#) HashCodeLocale.java
 * A class representing use of method hashCode() of Locale class
 in java.util Package.
 * @Version  24-May-2008
 @author   Rose India Team
 */
import java.util.*;

class HashCodeLocale {
    public static void mainString args[] ){

    /* Create object of Locale class using contructor 
         Locale(String language, String country, String variant) */
         Locale obj1 = new Locale("ENGLISh""Us""WIN");
       Locale obj2 = new Locale("CHINESE""China""MAC");
     System.out.println("object obj1 of Locale class is : "+obj1);
       System.out.println("object obj2 of Locale class is : "+obj2);
     // hashCode() method call.
         int hashCode = obj1.hashCode();
     System.out.println("Hash code for object obj1 : " + hashCode);
     hashCode = obj2.hashCode();
     System.out.println("Hash code for object obj2 : " + hashCode);
  }
}

Output of the program.
object objLocale1 of Locale class is : english_US_WIN
object objLocale2 of Locale class is : chinese_CHINA_MAC
Hash code for object obj1 : 1754169694
Hash code for object obj2 : 2145092295

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US