fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.util.stream.*;
  5. import java.lang.*;
  6. import java.io.*;
  7. import java.util.Arrays;
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. // Stream<String> fruitStream = Stream.of("apple", "banana", "pear", "kiwi", "orange");
  15.  
  16. // fruitStream.filter(s -> s.contains("a"))
  17. // .map(String::toUpperCase)
  18. // .sorted()
  19. // .forEach(System.out::println);
  20.  
  21. Stream<String> fruitStream = Stream.of("apple", "banana", "pineapple", "mango", "guava", "grapes");
  22.  
  23. fruitStream.filter(x -> x.contains("a"))
  24. .map(String::toUpperCase)
  25. .sorted()
  26. .forEach(System.out::println);
  27.  
  28. // try(Stream<String> lines = Files.lines(Paths.get("some_path"))){
  29. // lines.forEach(System.out::println);
  30. // }
  31.  
  32. // Stream.onClose("sdsf");
  33.  
  34. List<Integer> intStream = Arrays.asList(1, 2, 5, 4, 8 ,9, 7);
  35. intStream.stream().filter(x -> (x & 1) == 1).forEach(System.out::println);
  36.  
  37. List<String> list1 = Arrays.asList("one", "two");
  38. List<String> list2 = Arrays.asList("three", "four", "five");
  39. List<String> list3 = Arrays.asList("six");
  40.  
  41. List<String> finalList = Stream.of(list1, list2, list3).flatMap(Collection::stream).collect(Collectors.toList());
  42. System.out.println(finalList);
  43.  
  44.  
  45. }
  46.  
  47. // public Stream<String> streamAndDelete(Path path) throws IOExecption {
  48. // return Files.lines(path).onClose(() -> someClass.deletePath(path));
  49. // }
  50. }
Success #stdin #stdout 0.11s 56296KB
stdin
Standard input is empty
stdout
APPLE
BANANA
GRAPES
GUAVA
MANGO
PINEAPPLE
1
5
9
7
[one, two, three, four, five, six]