Files
hello-algo/en/codes/java/chapter_hashing/built_in_hash.java
T
Yudong JinandClaude Opus 5.5 4fd605c502 Correct and unify doc snippets; fix errors in the demo sources (#2039)
Code snippets in the book are corrected and unified across languages and
kept as literal blocks in the snippet files. The demo sources keep their
#2033 form, with fixes only for real errors: wrong code, wrong printed
labels, comments that contradict the code, and typos. en/ja/ko demos are
rendered from the reviewed code dictionaries (krahets/hello-algo-workspace#78).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-23 15:29:13 +08:00

39 lines
1.2 KiB
Java

/**
* File: built_in_hash.java
* Created Time: 2023-06-21
* Author: krahets ([email protected])
*/
package chapter_hashing;
import utils.*;
import java.util.*;
public class built_in_hash {
public static void main(String[] args) {
int num = 3;
int hashNum = Integer.hashCode(num);
System.out.println("Integer " + num + " has hash value " + hashNum);
boolean bol = true;
int hashBol = Boolean.hashCode(bol);
System.out.println("Boolean " + bol + " has hash value " + hashBol);
double dec = 3.14159;
int hashDec = Double.hashCode(dec);
System.out.println("Floating-point number " + dec + " has hash value " + hashDec);
String str = "Hello 算法";
int hashStr = str.hashCode();
System.out.println("String " + str + " has hash value " + hashStr);
Object[] arr = { 12836, "小哈" };
int hashTup = Arrays.hashCode(arr);
System.out.println("Array " + Arrays.toString(arr) + " has hash value " + hashTup);
ListNode obj = new ListNode(0);
int hashObj = obj.hashCode();
System.out.println("Node object " + obj + " has hash value " + hashObj);
}
}