-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctional1.java
More file actions
69 lines (60 loc) · 2.25 KB
/
Functional1.java
File metadata and controls
69 lines (60 loc) · 2.25 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
59
60
61
62
63
64
65
66
67
68
69
import java.util.List;
import java.util.stream.Collectors;
@SuppressWarnings("unused")
public class Functional1 {
/**
* Given a list of integers, return a list where each integer is multiplied by 2.
*/
public List<Integer> doubling(List<Integer> nums) {
return nums.stream().map(i -> i * 2).collect(Collectors.toList());
}
/**
* Given a list of integers, return a list where each integer is multiplied with itself.
*/
public List<Integer> square(List<Integer> nums) {
return nums.stream().map(i -> i * i).collect(Collectors.toList());
}
/**
* Given a list of strings, return a list where each string has "*" added at its end.
*/
public List<String> addStar(List<String> strings) {
return strings.stream().map(s -> s + "*").collect(Collectors.toList());
}
/**
* Given a list of strings, return a list where each string is replaced by
* 3 copies of the string concatenated together.
*/
public List<String> copies3(List<String> strings) {
return strings.stream().map(s -> s + s + s).collect(Collectors.toList());
}
/**
* Given a list of strings, return a list where each string has "y" added at its start and end.
*/
public List<String> moreY(List<String> strings) {
return strings.stream().map(s -> "y" + s + "y").collect(Collectors.toList());
}
/**
* Given a list of integers, return a list where each integer is added to 1 and the result is multiplied by 10.
*/
public List<Integer> math1(List<Integer> nums) {
return nums.stream().map(i -> 10 + i * 10).collect(Collectors.toList());
}
/**
* Given a list of non-negative integers, return an integer list of the rightmost digits. (Note: use %)
*/
public List<Integer> rightDigit(List<Integer> nums) {
return nums.stream().map(i -> i % 10).collect(Collectors.toList());
}
/**
* Given a list of strings, return a list where each string is converted to lower case (Note: String toLowerCase() method).
*/
public List<String> lower(List<String> strings) {
return strings.stream().map(String::toLowerCase).collect(Collectors.toList());
}
/**
* Given a list of strings, return a list where each string has all its "x" removed.
*/
public List<String> noX(List<String> strings) {
return strings.stream().map(s -> s.replace("x", "")).collect(Collectors.toList());
}
}