From External Iteration
To Internal Iteration
List<Long> nums = ...;
List<Long> nums2
= new ArrayList<>();
for (long n: nums) {
nums2.add(n*2L);
}
Before
From External Iteration
To 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 Iteration
To 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 Iteration
To Internal Iteration
List<Long> nums = ...;
List<Long> nums2 = nums.stream()
.map(
n -> n*2L
)
.collect(Collectors.toList());
After
Java in the Past, Java in the Future
Java in the Past, Java in the Future
Java in the Past, Java in the Future
Java in the Past, Java in the Future
Java in the Past, Java in the Future
Java in the Past, Java in the Future
Java in the Past, Java in the Future
Java in the Past, Java in the Future
Java in the Past, Java in the Future
Java in the Past, Java in the Future
Java in the Past, Java in the Future
Java in the Past, Java in the Future
Java in the Past, Java in the Future

Java in the Past, Java in the Future

  • 25.
    From External Iteration ToInternal Iteration List<Long> nums = ...; List<Long> nums2 = new ArrayList<>(); for (long n: nums) { nums2.add(n*2L); } Before
  • 26.
    From External Iteration ToInternal 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());
  • 27.
    From External Iteration ToInternal 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!
  • 28.
    From External Iteration ToInternal Iteration List<Long> nums = ...; List<Long> nums2 = nums.stream() .map( n -> n*2L ) .collect(Collectors.toList()); After