FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaGenerics/src/java_generics/SortingExamples.java at master · zeddysoft/JavaGenerics · GitHub
zeddysoft
/
JavaGenerics
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaGenerics
/
src
/
java_generics
/
SortingExamples.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
51 lines (41 loc) · 1.34 KB
Breadcrumbs
JavaGenerics
/
src
/
java_generics
/
SortingExamples.java
Copy path
File metadata and controls
51 lines (41 loc) · 1.34 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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package
java_generics
;
import
java
.
util
.
ArrayList
;
import
java
.
util
.
Comparator
;
import
java
.
util
.
List
;
/**
*
* @author Azeez.Taiwo
*/
public
class
SortingExamples
{
public
static
void
main
(
String
[]
args
) {
Person
donDraper
=
new
Person
(
"Don Draper"
,
89
);
Person
peggyOlson
=
new
Person
(
"Peggy Olson"
,
65
);
Person
bertCooper
=
new
Person
(
"Bert Cooper"
,
100
);
List
<
Person
>
madMen
=
new
ArrayList
<>();
madMen
.
add
(
donDraper
);
madMen
.
add
(
peggyOlson
);
madMen
.
add
(
bertCooper
);
List
<
Integer
>
a
=
new
ArrayList
<>();
a
.
add
(
1
);
a
.
add
(
2
);
a
.
add
(
3
);
final
Person
youngestCastMember
=
min
(
madMen
,
new
PersonComparator
());
System
.
out
.
println
(
youngestCastMember
);
System
.
out
.
println
(
min
(
a
,
Integer
::
compare
));
}
public
static
<
T
>
T
min
(
List
<
T
>
list
,
Comparator
<
T
>
comparator
) {
T
lowest
=
list
.
get
(
0
);
for
(
int
i
=
1
;
i
<
list
.
size
(); ++
i
) {
final
T
element
=
list
.
get
(
i
);
if
(
comparator
.
compare
(
element
,
lowest
) <
0
) {
lowest
=
element
;
}
}
return
lowest
;
}
}
Back
|
FazBrowse Home
|
New Git URL