Java对象类int hashCode()方法(带示例)
对象类inthashCode()
包java.lang.Object.hashCode()中提供了此方法。
此方法用于返回对象的哈希码。
语法:
int hashCode(){
}参数:
我们不会在Object方法中将任何对象作为参数传递。
返回值:
此方法的返回类型为int,表示此方法返回对象的哈希码,返回类型为int,表示哈希码为数字格式。
Java程序演示对象类hashCode()方法的示例
import java.lang.Object;
public class ObjectClass {
public static void main(String[] args) {
//为Integer类型创建一个新对象
Integer in = new Integer(10);
//显示Integer类对象的哈希码
System.out.println("The hashCode of Integer class object in is :" + in .hashCode());
//为String类型创建一个新对象
String str = new String("Hello, Welcome in java world");
//显示String类对象的哈希码
System.out.println("The hashCode of String class object str is :" + str.hashCode());
}
}输出结果
D:\Programs>javac ObjectClass.java D:\Programs>java ObjectClass The hashCode of Integer class object in is :10 The hashCode of String class object str is :508604331
热门推荐
1 带狗狗训练
4 听力训练狗狗
6 怎训练狗狗
7 腹肌训练狗狗
8 网球训练狗狗
9 记叙文训练狗狗
10 狗狗太凶怎么训练
11 核心力量训练狗狗
12 狗狗乱叫怎么训练
13 发音训练狗狗
14 怎么训练狗狗叼东西给主人
15 荆州训练狗狗
16 篮球训练狗狗
17 做训练狗狗
18 训练狗狗坐姿