java.lang.Character.Subset.hashCode()方法範例


java.lang.Character.Subset.hashCode() 方法返回標準的雜湊碼。

宣告

以下是java.lang.Character.Subset.hashCode()方法的宣告

public final int hashCode()

引數

  • NA

返回值

此方法返回該物件的雜湊碼值。

異常

  • NA

例子

下面的例子顯示java.lang.Character.Subset.hashCode()方法的使用。

package com.yiibai;

import java.lang.*;

public class CharacterSubsetDemo extends Character.Subset {
  
   // constructor of super class
   CharacterSubsetDemo(String s) {
      super(s); 
   }

   public static void main(String[] args) {

      CharacterSubsetDemo obj1 = new CharacterSubsetDemo("admin");
      CharacterSubsetDemo obj2 = new CharacterSubsetDemo("webmaster");
      CharacterSubsetDemo obj3 = new CharacterSubsetDemo("administrator");

      // returns a hash code value
      int retval = obj1.hashCode();
      System.out.println("Hash code of Object " + obj1 + " = " + retval);
      retval = obj2.hashCode();
      System.out.println("Hash code of Object " + obj2 + " = " + retval);
      retval = obj3.hashCode();
      System.out.println("Hash code of Object " + obj3 + " = " + retval);
   }
} 

讓我們來編譯和執行上面的程式,這將產生以下結果:

Hash code of Object admin = 1414159026
Hash code of Object webmaster = 1569228633
Hash code of Object administrator = 778966024