Last active
September 10, 2021 13:17
-
-
Save josejuan/b87ac23e255147696f8162cd09834b42 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.testing; | |
import java.util.List; | |
import java.util.stream.IntStream; | |
import static java.util.stream.Collectors.counting; | |
import static java.util.stream.Collectors.groupingBy; | |
import static java.util.stream.Collectors.toList; | |
public class Test { | |
public static void main(String[] args) { | |
// create objects and persist into memory | |
List<X> xs = IntStream.range(0, 1_000_000).mapToObj(n -> new X()).collect(toList()); | |
// count hashes | |
System.out.println(xs.stream() | |
.collect(groupingBy(System::identityHashCode, counting())) | |
.values() | |
.stream() | |
.filter(sz -> sz > 1) | |
.count()); | |
} | |
static class X { | |
} | |
} | |
/* output: 232 */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment