FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
OnJava8-Examples/collections/Statistics.java at master · CSapprenticeWT/OnJava8-Examples · GitHub
CSapprenticeWT
OnJava8-Examples
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
OnJava8-Examples
/
collections
/
Statistics.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
25 lines (24 loc) · 813 Bytes
Breadcrumbs
OnJava8-Examples
/
collections
/
Statistics.java
Copy path
File metadata and controls
25 lines (24 loc) · 813 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// collections/Statistics.java
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Simple demonstration of HashMap
import
java
.
util
.*;
public
class
Statistics
{
public
static
void
main
(
String
[]
args
) {
Random
rand
=
new
Random
(
47
);
Map
<
Integer
,
Integer
>
m
=
new
HashMap
<>();
for
(
int
i
=
0
;
i
<
10000
;
i
++) {
// Produce a number between 0 and 20:
int
r
=
rand
.
nextInt
(
20
);
Integer
freq
=
m
.
get
(
r
);
// [1]
m
.
put
(
r
,
freq
==
null
?
1
:
freq
+
1
);
}
System
.
out
.
println
(
m
);
}
}
/* Output:
{0=481, 1=502, 2=489, 3=508, 4=481, 5=503, 6=519,
7=471, 8=468, 9=549, 10=513, 11=531, 12=521, 13=506,
14=477, 15=497, 16=533, 17=509, 18=478, 19=464}
*/
Back
|
FazBrowse Home
|
New Git URL