Date post: | 13-Apr-2017 |
Category: |
Technology |
Upload: | yuichi-sakuraba |
View: | 438 times |
Download: | 5 times |
From External IterationTo Internal Iteration
List<Long> nums = ...;List<Long> nums2 = new ArrayList<>();
for (long n: nums) { nums2.add(n*2L);}
BeforeList<Long> nums = ...;
List<Long> nums2 = nums.stream() .map(new Function<Long,Long>(){ @Override public Long aply(Long n) { return n*2L; } }) .collect(Collectors.toList());
List<Long> nums = ...;
List<Long> nums2 = nums.stream() .map(new Function<Long,Long>(){ @Override public Long aply(Long n) { return n*2L; } }) .collect(Collectors.toList());
Boilerplate!
List<Long> nums = ...;
List<Long> nums2 = nums.stream() .map(
n -> n*2L ) .collect(Collectors.toList());
After
From External IterationTo Internal Iteration
List<Long> nums = ...;
List<Long> nums2 = nums.stream() .map(new Function<Long,Long>(){ @Override public Long aply(Long n) { return n*2L; } }) .collect(Collectors.toList());
From External IterationTo Internal Iteration
List<Long> nums = ...;
List<Long> nums2 = nums.stream() .map(new Function<Long,Long>(){ @Override public Long aply(Long n) { return n*2L; } }) .collect(Collectors.toList());
Boilerplate!
From External IterationTo Internal Iteration
List<Long> nums = ...;
List<Long> nums2 = nums.stream() .map(
n -> n*2L ) .collect(Collectors.toList());
After