{}
CYBER CYBER CYBER CYBER CYBER
66
%OFF
Week Week Week Week Week

Stop copy pasting code you don't actually understand

Build the coding confidence you need to become a developer companies will fight for

Stop copy pasting code you don't actually understand

Become a PRO
Become a PRO
CYBER CYBER CYBER CYBER CYBER
66
%OFF
Week Week Week Week Week

Stop copy pasting code you don't actually understand

Build the coding confidence you need to become a developer companies will fight for

Stop copy pasting code you don't actually understand

Become a PRO
Become a PRO
run-icon
Main.java
// Online Java Compiler // Use this editor to write, compile and run your Java code online class Main { static class Test1 { static final java.util.Random r = new java.util.Random(); final int val; final int hash = r.nextInt(); public Test1(int v) { this.val = v; } public String toString() { return String.valueOf(val); } public int hashCode() { return hash; } } static class Test2 { final int val; public Test2(int v) { this.val = v; } public String toString() { return String.valueOf(val); } public int hashCode() { return val; } } public static void main(String[] args) { var s1 = new java.util.HashSet<Test1>(); s1.add(new Test1(1)); s1.add(new Test1(2)); s1.add(new Test1(3)); var s2 = new java.util.HashSet<Test2>(); s2.add(new Test2(1)); s2.add(new Test2(2)); s2.add(new Test2(3)); System.out.println(s1); // порядок меняется так как меняются хеши System.out.println(s2); // порядок стабильный так как хеши не меняются } }
Output