fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.function.ToIntFunction;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. static int counter = 0;
  12.  
  13. public static void main(String[] args) {
  14. foo2(Collections.nCopies(100, "X"), s -> {
  15. counter++;
  16. return s.length();
  17. });
  18. System.out.println(counter);
  19. }
  20.  
  21. static <T> void foo2(Collection<? extends T> collection, ToIntFunction<? super T> function) {
  22. collection.stream()
  23. .max(Comparator.comparingInt(function))
  24. .get();
  25. }
  26. }
Success #stdin #stdout 0.2s 320832KB
stdin
Standard input is empty
stdout
198