I have the following code:
Set<Integer> l = new TreeSet<>();
l.add(1);
l.add(10);
l.add(3);
l.add(-3);
l.add(-4);
and I want to unorder the collection with:
l.stream().unordered().forEach(System.out::println);
but the forEach returns always the collection ordered!
Then I have also another doubt about this sentence:
For sequential streams, the presence or absence of an encounter order does not affect performance, only determinism. If a stream is ordered, repeated execution of identical stream pipelines on an identical source will produce an identical result; if it is not ordered, repeated execution might produce different results.
In fact if a try this code on an unordered stream the results is always the same and never produce different results:
Arrays.stream( new int[]{8, -1, 3}).forEach(System.out::println);
Arrays.stream( new int[]{8, -1, 3}).forEach(System.out::println);
I really don't understand this API part...
Aucun commentaire:
Enregistrer un commentaire