java in the past, java in the future

Post on 13-Apr-2017

442 Views

Category:

Technology

5 Downloads

Preview:

Click to see full reader

TRANSCRIPT

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

top related