import java.util.*; import java.util.stream.*; public class Main{ public static void main(String[] args) { ArrayList<Integer> al=new ArrayList<>(); al.add(7); al.add(90); al.add(4); al.add(18); al.add(3); System.out.println("List : "+al); Optional<Integer> sum=al.stream().reduce((x,y)->(x+y)); if(sum.isPresent()) System.out.println(" sum :"+sum.get()); sum=al.stream().reduce((x,y)->(x*y)); if(sum.isPresent()) { System.out.println("product : "+sum.get()); } } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter