fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.util.stream.*;
  5. import java.util.function.*;
  6. import java.lang.*;
  7. import java.io.*;
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone {
  11. public static<R,U> List<R> myMap(Stream<U> s, Function<U,R> fnctn) {
  12. return s.reduce(
  13. new ArrayList<R>(),
  14. (List<R> list, U elem) -> { list.add(fnctn.apply(elem)); return list; },
  15. (List<R> list1, List<R> list2) -> { list1.addAll(list2); return list1; }
  16. );
  17. }
  18.  
  19. public static void main (String[] args) throws java.lang.Exception {
  20. List<String> words = Arrays.asList("word1", "word2", "word3");
  21. System.out.println(myMap(words.stream(), s->Integer.valueOf(s.substring(s.length()-1))));
  22. }
  23. }
Success #stdin #stdout 0.13s 4386816KB
stdin
Standard input is empty
stdout
[1, 2, 3]