fork download
  1. import java.util.*;
  2. import java.lang.*;
  3.  
  4.  
  5. class Main
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. testIterable(convertToArray(getStringList()));
  10.  
  11. }
  12.  
  13. public static String[] convertToArray(ArrayList<String> stringList){
  14. String[] stringArray = new String[stringList.size()];
  15. // If we use toArray() without an argument, it will return Object[]
  16. return stringList.toArray(stringArray);
  17. }
  18.  
  19. public static ArrayList<String> getStringList(){
  20. ArrayList<String> stringList = new ArrayList<String>();
  21.  
  22. stringList.add("String one");
  23. stringList.add("String two");
  24.  
  25. return stringList;
  26.  
  27. }
  28.  
  29. public static void testIterable(Object...objects){
  30. for(Object object : objects){
  31. System.out.println("Object: "+ object.toString());
  32. }
  33. }
  34. }
Success #stdin #stdout 0.06s 380160KB
stdin
Standard input is empty
stdout
Object: String one
Object: String two