How is Stream.distinct() working? #javalanguage #javacoding #javatips #javacodinginterview

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

If the stream pushes different elements to downstream immediately after putting it in the hashset and getting true, why does it have to use LinkedHashSet for ordered stream? Isn't hashset just used to see if it should push the elements to downstream?

srki
Автор

this is super interesting, because it means that for a stream of size N, if you use distinct the memory space may be duplicated

EdgarLopezAnaya
Автор

i never looked at the code, i admit, but i also also would have guessed and hoped that distinct() on an *sorted* stream would only need to check adjacent items (or at least those pairs that compare to 0) for equality rather than gathering (before Gatherers) them into a set at all... He doesn't mention sorted streams, so maybe?

StrangerNoises
Автор

I am first year computer science currently learning java is this something I will be learning?

naps
welcome to shbcf.ru