fork(1) 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.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. List<String> list1 = Arrays.asList("A", "XYZ", "AXTU");
  14. List<Integer> list2 = Arrays.asList(2, 4, 6);
  15. Stream<Object> stream = Stream.concat(list1.stream(), list2.stream());
  16. System.out.println(stream.sorted((Object o1, Object o2) -> {
  17. return (o1 instanceof String ? 2*((String)o1).length() : 1+2*(Integer)o1)
  18. - (o2 instanceof String ? 2*((String)o2).length() : 1+2*(Integer)o2);
  19. }).collect(Collectors.toList()));
  20. }
  21. }
Success #stdin #stdout 0.2s 320832KB
stdin
Standard input is empty
stdout
[A, 2, XYZ, AXTU, 4, 6]