'Fixed formatting;'

This commit is contained in:
Arkadiusz Hypki 2024-05-20 17:49:51 +02:00
parent 96a395a6e3
commit 044990ab6c
2 changed files with 11 additions and 8 deletions

View File

@ -18,7 +18,8 @@ public class Parallel {
// map // map
System.out.println("Computing squares (with limit and sort): "); System.out.println("Computing squares (with limit and sort): ");
List<Integer> numbers = Arrays.asList(2,3,4,5); List<Integer> numbers = Arrays.asList(2,3,4,5);
numbers.stream() numbers
.stream()
.map(x -> x *x) // Function .map(x -> x *x) // Function
.sorted() .sorted()
.limit(2) .limit(2)
@ -33,15 +34,16 @@ public class Parallel {
.stream() .stream()
.filter(s -> s.startsWith("S")) // Predicate .filter(s -> s.startsWith("S")) // Predicate
.collect(Collectors.toList()) .collect(Collectors.toList())
.forEach(System.out::println);; .forEach(System.out::println);
// print output -> [Sally, Sephora] // print output -> [Sally, Sephora]
// sorted // sorted
System.out.println("Sorting names: "); System.out.println("Sorting names: ");
names.stream() names
.stream()
.sorted() .sorted()
.collect(Collectors.toList()) .collect(Collectors.toList())
.forEach(System.out::println);; .forEach(System.out::println);
// print output -> [Harry, Sally, Sephora] // print output -> [Harry, Sally, Sephora]
// reduce // reduce
@ -79,16 +81,17 @@ public class Parallel {
.stream() .stream()
.skip(1) .skip(1)
.collect(Collectors.toList()) .collect(Collectors.toList())
.forEach(System.out::println);; .forEach(System.out::println);
// print output -> [3,4,5] // print output -> [3,4,5]
System.out.println("Computing squares in parallel: "); System.out.println("Computing squares in parallel: ");
numbers.stream() numbers
.stream()
.parallel() // add this line here .parallel() // add this line here
.map(x -> x *x) .map(x -> x *x)
.sorted() .sorted()
.limit(2) .limit(2)
.collect(Collectors.toList()) .collect(Collectors.toList())
.forEach(System.out::println);; .forEach(System.out::println);
} }
} }