位置:首页 > Java技术 > java.lang > java.lang.Character.Subset.hashCode()方法实例

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