import java.util.*;
import java.util.stream.*;
public class MappingDemo {
public static void main(String[] args) {
ArrayList<Integer> al = new ArrayList<>();
al.add(5);
al.add(16);
al.add(25);
al.add(30);
al.add(49);
al.add(100);
System.out.println("Actual List: " + al);
Stream<Double> sqr = al.stream().map(n -> Math.sqrt(n));
System.out.print("Square roots: ");
sqr.forEach(n -> System.out.print("[" + n + "] "));
System.out.println();
}
}
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