-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKata2.java
More file actions
45 lines (37 loc) · 1.53 KB
/
Copy pathKata2.java
File metadata and controls
45 lines (37 loc) · 1.53 KB
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
package algo.basics;
import java.util.List;
import java.util.stream.Collectors;
public class Kata2 {
public static int countByPromotion(int promotionYear, List<String> stdList){
// On convertit l'année en string et on recupère les 2 dernières lettres
String lastTwoLetters = String.valueOf(promotionYear).substring(2);
// Filtrer la liste des STD et compter ce qui reste
// Filtrer : ceux qui ont ces 2 dernières lettres juste après "STD"
return stdList.stream()
.filter(std -> std.substring(3,5).equals(lastTwoLetters))
.collect(Collectors.toList())
.size();
// lorsque vous comparez des objets, utilisez "equals"
// == marche seulement pour les types primitfs : int, float.
}
public static int countByCity(List<String> cities, String city){
return cities.stream()
.filter(address -> address.toLowerCase().contains(city.toLowerCase()))
.collect(Collectors.toList())
.size();
}
public static void main(String[] args) {
List<String> list = List.of(
"STD21001",
"STD21002",
"STD23005",
"STD21015",
"STD22088",
"STD22103",
"STD30009"
);
System.out.println(Kata2.countByPromotion(2021, list)); //3
System.out.println(Kata2.countByPromotion(2022, list)); //2
System.out.println(Kata2.countByPromotion(2030, list)); //1
}
}