FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
OnJava8-Examples/collections/MapOfList.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
/
MapOfList.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
65 lines (64 loc) · 1.91 KB
Breadcrumbs
OnJava8-Examples
/
collections
/
MapOfList.java
Copy path
File metadata and controls
65 lines (64 loc) · 1.91 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// collections/MapOfList.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.
// {java collections.MapOfList}
package
collections
;
import
reflection
.
pets
.*;
import
java
.
util
.*;
public
class
MapOfList
{
public
static
final
Map
<
Person
,
List
< ?
extends
Pet
>>
petPeople
=
new
HashMap
<>();
static
{
petPeople
.
put
(
new
Person
(
"Dawn"
),
Arrays
.
asList
(
new
Cymric
(
"Molly"
),
new
Mutt
(
"Spot"
)));
petPeople
.
put
(
new
Person
(
"Kate"
),
Arrays
.
asList
(
new
Cat
(
"Shackleton"
),
new
Cat
(
"Elsie May"
),
new
Dog
(
"Margrett"
)));
petPeople
.
put
(
new
Person
(
"Marilyn"
),
Arrays
.
asList
(
new
Pug
(
"Louie aka Louis Snorkelstein Dupree"
),
new
Cat
(
"Stanford"
),
new
Cat
(
"Pinkola"
)));
petPeople
.
put
(
new
Person
(
"Luke"
),
Arrays
.
asList
(
new
Rat
(
"Fuzzy"
),
new
Rat
(
"Fizzy"
)));
petPeople
.
put
(
new
Person
(
"Isaac"
),
Arrays
.
asList
(
new
Rat
(
"Freckly"
)));
}
public
static
void
main
(
String
[]
args
) {
System
.
out
.
println
(
"People: "
+
petPeople
.
keySet
());
System
.
out
.
println
(
"Pets: "
+
petPeople
.
values
());
for
(
Person
person
:
petPeople
.
keySet
()) {
System
.
out
.
println
(
person
+
" has:"
);
for
(
Pet
pet
:
petPeople
.
get
(
person
))
System
.
out
.
println
(
" "
+
pet
);
}
}
}
/* Output:
People: [Person Dawn, Person Kate, Person Isaac, Person
Marilyn, Person Luke]
Pets: [[Cymric Molly, Mutt Spot], [Cat Shackleton, Cat
Elsie May, Dog Margrett], [Rat Freckly], [Pug Louie aka
Louis Snorkelstein Dupree, Cat Stanford, Cat Pinkola],
[Rat Fuzzy, Rat Fizzy]]
Person Dawn has:
Cymric Molly
Mutt Spot
Person Kate has:
Cat Shackleton
Cat Elsie May
Dog Margrett
Person Isaac has:
Rat Freckly
Person Marilyn has:
Pug Louie aka Louis Snorkelstein Dupree
Cat Stanford
Cat Pinkola
Person Luke has:
Rat Fuzzy
Rat Fizzy
*/
Back
|
FazBrowse Home
|
New Git URL