How to get a string [] consisting of calls to .toString () of an ArrayList <Object> in one line

So I'm wondering if it is possible to populate a String array from calls toString () of an ArrayList

So, I know that this can be done with a loop, but is there one approach?

Cyclic approach

ArrayList<Object> objects = new ArrayList<Object>(); //fill object with elements // String[] strings = new String[object.length()]; for(int i = 0;i<10;i++)strings[i]=objects.get(i).toString(); 
+5
source share
1 answer

Using java-8,

 String[] strings = objects.stream().map(Object::toString).toArray(String[]::new); 
+11
source

All Articles