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.ArrayList;
  7. import java.util.List;
  8. import java.util.Objects;
  9.  
  10. /* Name of the class has to be "Main" only if the class is public. */
  11. class Ideone
  12. {
  13. public static void main (String[] args) throws java.lang.Exception
  14. {
  15. List<Integer> ints = new ArrayList<Integer>();
  16. List<Double> doubles = new ArrayList<Double>();
  17. check(null);
  18. check(ints);
  19. ints.add(1);
  20. check(ints);
  21. doubles.add(1D);
  22. check(doubles);
  23. }
  24.  
  25. public static void check(List<?> list) {
  26. if (Objects.equals(null, list))
  27. System.out.println("null");
  28. else if (list.isEmpty())
  29. System.out.println("empty");
  30. else if (list.get(0) instanceof Integer)
  31. System.out.println("int");
  32. else if (list.get(0) instanceof Double)
  33. System.out.println("double");
  34. }
  35. }
Success #stdin #stdout 0.1s 320512KB
stdin
Standard input is empty
stdout
null
empty
int
double