fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.stream.*;
  4. import java.util.*;
  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. Optional<Long> opt1 = Optional.of(13l);
  14. Optional<String> opt2 = Optional.empty();
  15. Optional<String> opt3 = Optional.of("something");
  16.  
  17. Stream<Optional> fields = Stream.of(opt1, opt2, opt3);
  18. List<String> result = fields.map(o -> o.orElse("")).map(o -> o.toString()).collect(Collectors.toList());
  19. System.out.println(result);
  20. }
  21. }
Success #stdin #stdout 0.12s 4386816KB
stdin
Standard input is empty
stdout
[13, , something]