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.

59 lines
1.9 KiB

## StreamCollect
### Instructions
Create a file `StreamCollect.java`.
CON-1881-Review-java-piscine-subjects-Fix-grammar-and-semantic-issues (#2102) * docs(java piscine): Review and update AdventureAbstract exercise * docs(java piscine): Review AdventureCharacter subject * docs(java piscine): Review AdventureInterface subject * docs(java piscine): Review AdventureMonster subject * docs(java piscine): review AdventureSorcerer subject * docs(java piscine): Review AdventureTemplar subject * docs(java piscine): Review AdventureUtils subject * docs(java piscine): Review AdventureWeapon subject * docs(java piscine): Review ComputeArray subject * docs(java piscine): Review FileSearch subject * docs(java piscine): Review FormatDate subject * docs(java piscine): Review KeepTheChange subject * docs(java piscine): Review ListEquals subject * docs(java piscine): Review MapInventory subject * docs(java piscine): Review Observer subject * docs(java piscine): Review Palindrome subject * docs(java piscine): Review RegexReplace subject * docs(java piscine): Review Singleton subject * docs(java piscine): Review StarConstructors subject * docs(java piscine): Review StarGalaxy subject * docs(java piscine): Review StarMass subject * docs(java piscine): Review StarOverride subject * docs(java piscine): Review StarPlanet subject * docs(java piscine): Review StarProperties subject * docs(java piscine): Review StarStatic subject * docs(java piscine): Review StarUtils subject * docs(java piscine): Review StreamCollect subject * docs(java piscine): Review StreamMap subject * docs(java piscine): Review StreamReduce subject * docs(java piscine): Review StringConcat subject * docs(java piscine): Review StringContains subject * docs(java piscine): Review Wedding subject * docs(java piscine): Review WeddingComplex subject * docs(java piscine): Change a part of RegexReplace subject * docs(java piscine): Update AdventureAbstract subject * docs(java piscine): Fix wrong naming parameter -> attribute * docs(java piscine): Remove empty lines * docs(java piscine): Remove ## from line
1 year ago
Create a function `mapByFirstLetter` which maps the first letter (to upper case) to a list of Strings begining with the given letter.
Create a function `getMaxByModulo4` which groups the integers by modulo 4 and returns a map associating each module 4 value to the max integer in each group.
Create a function `orderAndConcatWithSharp` which joins the alphabetically sorted Strings with a ' # ' between each. The resulting String starts with a '{' and ends with a '}'.
### Expected Functions
```java
public class StreamCollect {
public static Map<Character, List<String>> mapByFirstLetter(Stream<String> s) {
// your code here
}
public static Map<Integer, Optional<Integer>> getMaxByModulo4(Stream<Integer> s) {
// your code here
}
public static String orderAndConcatWithSharp(Stream<String> s) {
// your code here
}
}
```
### Usage
Here is a possible ExerciseRunner.java to test your function :
```java
import java.util.stream.Stream;
public class ExerciseRunner {
public static void main(String[] args) {
System.out.println(StreamCollect.mapByFirstLetter(Stream.of("Bonjour", "le", "monde !", "bonsoir")));
System.out.println(StreamCollect.getMaxByModulo4(Stream.of(5, 12, 32, 4, 9, 17, 98, 424, 97, 5843, 48354)));
System.out.println(StreamCollect.orderAndConcatWithSharp(Stream.of("Hello", "how are you ?", "where do you live ?", "Bordeaux")));
}
}
```
and its output :
```shell
$ javac *.java -d build
$ java -cp build ExerciseRunner
{B=[Bonjour, bonsoir], L=[le], M=[monde !]}
{0=Optional[424], 1=Optional[97], 2=Optional[48354], 3=Optional[5843]}
##{Bordeaux # Hello # how are you ? # where do you live ?}
$
```
### Notions
[Stream](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/stream/Stream.html)