MCPcopy Index your code
hub / github.com/BruceEckel/OnJava8-Examples / main

Method main

collections/Statistics.java:9–19  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

7
8public class Statistics {
9 public static void main(String[] args) {
10 Random rand = new Random(47);
11 Map<Integer, Integer> m = new HashMap<>();
12 for(int i = 0; i < 10000; i++) {
13 // Produce a number between 0 and 20:
14 int r = rand.nextInt(20);
15 Integer freq = m.get(r); // [1]
16 m.put(r, freq == null ? 1 : freq + 1);
17 }
18 System.out.println(m);
19 }
20}
21/* Output:
22{0=481, 1=502, 2=489, 3=508, 4=481, 5=503, 6=519,

Callers

nothing calls this directly

Calls 2

getMethod · 0.65
putMethod · 0.45

Tested by

no test coverage detected