mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.6 KiB
58 lines
1.6 KiB
1 year ago
|
## StreamMap
|
||
|
|
||
|
### Instructions
|
||
|
|
||
|
Create a file `StreamMap.java`.
|
||
|
|
||
|
Create a function `sumOfStringLength` which returns the sum of the length of the strings in the stream.
|
||
|
Create e function `upperCaseAllString` which returns the list of all the strings in upper case as stream.
|
||
|
Create e function `uniqIntValuesGreaterThan42` which keep only double greater than 42, transforms the double in integer and return them as a set.
|
||
|
|
||
|
|
||
|
### Expected Functions
|
||
|
```java
|
||
|
public class StreamMap {
|
||
|
public static Integer sumOfStringLength(Stream<String> s) {
|
||
|
// your code here
|
||
|
}
|
||
|
|
||
|
public static List<String> upperCaseAllString(Stream<String> s) {
|
||
|
// your code here
|
||
|
}
|
||
|
|
||
|
public static Set<Integer> uniqIntValuesGreaterThan42(Stream<Double> s) {
|
||
|
// your code here
|
||
|
}
|
||
|
}
|
||
|
```
|
||
|
|
||
|
### Usage
|
||
|
|
||
|
Here is a possible ExerciseRunner.java to test your function :
|
||
|
|
||
|
```java
|
||
|
import java.io.IOException;
|
||
|
import java.util.stream.Stream;
|
||
|
|
||
|
public class ExerciseRunner {
|
||
|
public static void main(String[] args) throws IOException {
|
||
|
System.out.println(StreamMap.sumOfStringLength(Stream.of("Bonjour", "le", "monde !")));
|
||
|
System.out.println(StreamMap.upperCaseAllString(Stream.of("IL", "Fait", "beaU !!")));
|
||
|
System.out.println(StreamMap.uniqIntValuesGreaterThan42(Stream.of(23.439, 42.34, 39194.4)));
|
||
|
}
|
||
|
}
|
||
|
```
|
||
|
|
||
|
and its output :
|
||
|
```shell
|
||
|
$ javac *.java -d build
|
||
|
$ java -cp build ExerciseRunner
|
||
|
16
|
||
|
[IL, FAIT, BEAU !!]
|
||
|
[42, 39194]
|
||
|
$
|
||
|
```
|
||
|
|
||
|
### Notions
|
||
|
[Stream](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/stream/Stream.html)
|