Last active
March 16, 2021 08:58
-
-
Save ricciotto-in-nebbia/7db47e0f9d0b2319c9a126d9f65c187c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StreamAPI { | |
//calculator | |
// public static void main(String[] args) { | |
// MyInterface<Double> myInter = (x, y) -> (x + y / 100 * 25); | |
// System.out.println(myInter.myMethod(30.2, 100.56)); | |
// } | |
// interface MyInterface<T> { | |
// T myMethod(T a, T b); | |
// } | |
//calculator | |
// public static void main(String[] args) { | |
// BinaryOperator<Double> op1 = (d1, d2) -> (d1 + d2 - (d1 / d2 + 117) - 345); | |
// BinaryOperator<Double> op2 = (d1, d2) -> (d1 * d2); | |
// System.out.println(calculate(30.0, 250.13, op1)); | |
// System.out.println(calculate(30.0, 250.13, op2)); | |
// } | |
// private static double calculate(double d1, double d2, BinaryOperator b) { | |
// return (double) b.apply(d1, d2); | |
// } | |
// 1908 | |
// bfWriter.write(Files.lines(Paths.get(fileRead)) | |
// .map(word -> Arrays.stream(word.split(" ")) | |
// .filter(e -> e.matches("\\d+")) | |
// .collect(Collectors.joining(" "))) | |
// .collect(Collectors.joining())); | |
// | |
// | |
// 1821 | |
// Files.lines(Paths.get(fileName)) | |
// .collect(Collectors.joining(System.lineSeparator())) | |
// .chars() | |
// .mapToObj(i -> (char) i) | |
// .collect(Collectors.groupingBy(v -> v, Collectors.counting())) | |
// .entrySet().stream() | |
// .sorted((e1, e2) -> e1.getKey().compareTo(e2.getKey())) | |
// .forEach((k) -> System.out.println(k.getKey() + " " + k.getValue())); | |
// 2018 | |
// public static Map<String, Long> countWords(ArrayList<String> list) { | |
// return list.stream().collect(Collectors.groupingBy(e -> e, Collectors.counting())); | |
// 1907 | |
// String fileName = null; | |
// try ( | |
// BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) { | |
// fileName = reader.readLine(); | |
// System.out.println( | |
// Files.lines(Paths.get(fileName)) | |
// .flatMap((p) -> Arrays.stream(p.split("\\W"))) | |
// .filter("world"::equals) | |
// .count()); | |
// } catch ( | |
// IOException e) { | |
// e.printStackTrace(); | |
// } | |
// 2208 | |
// return params.entrySet().stream() | |
// .filter(e -> nonNull(e.getValue())) | |
// .map(e -> e.getKey() + " = '" + e.getValue() + "'") | |
// .collect(Collectors.joining(" and ")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment