fork(1) download
  1. import java.util.*;
  2.  
  3. class Main {
  4. public static void main (String[] args) {
  5. System.out.println(getCount(getPlayers()));
  6. System.out.println(getCount(getPlayers0()));
  7. }
  8.  
  9. public static Object[] getPlayers() {
  10. return new Object[] { new Object(), new Object() };
  11. }
  12.  
  13. public static Collection<?> getPlayers0() {
  14. return new ArrayList(Arrays.asList(new Object[] { new Object(), new Object() }));
  15. }
  16.  
  17. public static int getCount(Object collect) {
  18. if (collect instanceof Collection) {
  19. return ((Collection) collect).size();
  20. } else {
  21. return ((Object[]) collect).length;
  22. }
  23. }
  24. }
Success #stdin #stdout 0.08s 380160KB
stdin
Standard input is empty
stdout
2
2