Skip to content

Instantly share code, notes, and snippets.

@ucguy4u
Created September 19, 2020 15:03
Show Gist options
  • Save ucguy4u/b2bb17f5725d03b8b638a2829398da40 to your computer and use it in GitHub Desktop.
Save ucguy4u/b2bb17f5725d03b8b638a2829398da40 to your computer and use it in GitHub Desktop.
package com.ucguy4u.functional.java;
import java.util.Arrays;
import java.util.stream.IntStream;
import java.util.stream.Stream;
/**
*
* @author chauhanuday
*/
public class Lambdas_06 {
public static void main(String[] args) {
IntStream.range(1, 4).forEach(System.out::println);
// find the average of the numbers squared
Arrays.stream(new int[] { 1, 2, 3, 4 }).map(n -> n * n).average().ifPresent(System.out::println);
// map doubles to ints
Stream.of(1.5, 2.3, 3.7).mapToInt(Double::intValue).forEach(System.out::println);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment