Skip to content

Instantly share code, notes, and snippets.

@ricciotto-in-nebbia
Last active March 16, 2021 08:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ricciotto-in-nebbia/7db47e0f9d0b2319c9a126d9f65c187c to your computer and use it in GitHub Desktop.
Save ricciotto-in-nebbia/7db47e0f9d0b2319c9a126d9f65c187c to your computer and use it in GitHub Desktop.
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) -&gt; Arrays.stream(p.split("\\W")))
// .filter("world"::equals)
// .count());
// } catch (
// IOException e) {
// e.printStackTrace();
// }
// 2208
// return params.entrySet().stream()
// .filter(e -&gt; nonNull(e.getValue()))
// .map(e -&gt; 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