-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDocumentation.java
More file actions
58 lines (47 loc) · 1.79 KB
/
Copy pathDocumentation.java
File metadata and controls
58 lines (47 loc) · 1.79 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
46
47
48
49
50
51
52
53
54
55
56
57
58
package algo.basics;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
/**
* A simple class documenting various functions and methods that can be used in Katas for Java
*/
public class Documentation {
public static void main(String[] args) {
// JOIN
String[] array = {"Bon","jour","no","!"};
String result = String.join("", array);
// Autre manière à part STREAM
String result2 = Arrays.stream(array)
.collect(Collectors.joining());
// SPLIT
String string = "Root me is awesome!";
string.split(" ");
// REPEAT
"bye".repeat(2); // byebye
"-".repeat(100);
// INDEXOF
String someString = "Hello";
someString.indexOf("e"); // 1
// FILTER
List<Integer> listeEntiers = Arrays.asList(1,2,3,4,5,6,7);
List<Integer> arrayOdd = listeEntiers.stream()
.filter(num -> num % 2 != 0)
.collect(Collectors.toList());
// SUBSTRING
String word = "Java is bae";
word.substring(0,3); // 0 = index de début, 3 = index de fin EXCLU
// MAP
List<Integer> squareValues = listeEntiers.stream()
.map(number -> number * number)
.collect(Collectors.toList());
// SORT
Collections.sort(listeEntiers); // le tableau original est affecté !
listeEntiers.stream().sorted((a, b) -> b - a); // le tableau original n'est pas affecté
// SORT By length
List<String> words = Arrays.asList("Bonjour", "Anticonstitutionnellement", "Kayak");
List<String> sorted = words.stream()
.sorted((a,b) -> b.length() - a.length())
.collect(Collectors.toList());
}
}