Skip to content

Commit 204ad95

Browse files
Merge remote-tracking branch 'origin/master'
2 parents 429c700 + cc089e5 commit 204ad95

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.baeldung.java_8_features;
2+
3+
public class Person {
4+
private String name;
5+
private Integer age;
6+
7+
public Person(String name, int age) {
8+
this.name = name;
9+
this.age = age;
10+
}
11+
12+
public String getName() {
13+
return name;
14+
}
15+
16+
public void setName(String name) {
17+
this.name = name;
18+
}
19+
20+
public Integer getAge() {
21+
return age;
22+
}
23+
24+
public void setAge(Integer age) {
25+
this.age = age;
26+
}
27+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.baeldung.java8;
2+
3+
import com.baeldung.java_8_features.Person;
4+
import org.junit.Test;
5+
6+
import java.util.Arrays;
7+
import java.util.List;
8+
9+
import static org.junit.Assert.assertEquals;
10+
11+
public class Java8MaxMinTest {
12+
13+
@Test
14+
public void whenListIsOfIntegerThenMaxCanBeDoneUsingIntegerComparator() {
15+
//given
16+
final List<Integer> listOfIntegers = Arrays.asList(1, 2, 3, 4, 56, 7, 89, 10);
17+
final Integer expectedResult = 89;
18+
19+
//then
20+
assertEquals(expectedResult,
21+
(Integer) listOfIntegers.stream().mapToInt(val -> val).max().getAsInt());
22+
}
23+
24+
@Test
25+
public void whenListIsOfPersonObjectThenMinCanBeDoneUsingCustomComparatorThroughLambda() {
26+
//given
27+
final Person alex = new Person("Alex", 23);
28+
final Person john = new Person("John", 40);
29+
final Person peter = new Person("Peter", 32);
30+
final List<Person> people = Arrays.asList(alex, john, peter);
31+
32+
//then
33+
assertEquals("Alex must be having min age", alex,
34+
people.stream().min((o1, o2) -> o1.getAge().compareTo(o2.getAge())).get());
35+
}
36+
37+
}

0 commit comments

Comments
 (0)