目录

int hashCode()

描述 (Description)

java.lang.Integer.hashCode()方法返回此Integer的哈希码。

声明 (Declaration)

以下是java.lang.Integer.hashCode()方法的声明

public int hashCode()

参数 (Parameters)

NA

返回值 (Return Value)

此方法返回此对象的哈希码值,等于此Integer对象表示的原始int值。

异常 (Exception)

NA

例子 (Example)

以下示例显示了java.lang.Integer.hashCode()方法的用法。

package com.iowiki;
import java.lang.*;
public class IntegerDemo {
   public static void main(String[] args) {
      Integer i = new Integer("20");
      /* returns a hash code value for this object, equal to the primitive
         int value represented by this Integer object */
      int retval = i.hashCode();
      System.out.println("Value = " + retval);
   }
}

让我们编译并运行上面的程序,这将产生以下结果 -

Value = 20
↑回到顶部↑
WIKI教程 @2018