Hi guys. Given sentence for example: ala ma kota, kot koduje w Javie kota I should to every letter occurring in the sentence I should map every string that this letter contains. So the output should be:
I have written algorithm for it, but I think that there is a better way do to this using streams (or somehow else).
And these two methods which are placed in other class:
Fred Rosenberger told me off for simply writing fewer lines once. Yes, quality code is often shorter than poor code, but simply counting lines can tempt people to format their code badly.
Piet, please explain the compute if absent code a bit more.
computeIfAbsent takes a key and a function. If there is already a non-null value in the map for the key, it is returned. Otherwise, the function is called with the key as argument. The result of the function call, if not null, will be inserted into the map. It will also be returned (even if it's null).
In this case, the function will return a new set. The result will therefore be a non-null set - either the existing non-null set, or the newly created one. By calling add on this return value you save one get call on the map, making it slightly more efficient.