Java Collection toArray() Method: Convert Collection to Array
This method returns an array containing all of the elements in the collection in the same order as the original collection. The returned array is an Object array, which means that the type of the elements in the array is not specified. The size of the returned array is equal to the size of the collection.
Syntax:
public Object[] toArray()
Example:
List<String> list = new ArrayList<>();
list.add('apple');
list.add('banana');
list.add('orange');
Object[] array = list.toArray();
for (Object obj : array) {
System.out.println(obj); // prints 'apple', 'banana', 'orange'
}
原文地址: https://www.cveoy.top/t/topic/n0zf 著作权归作者所有。请勿转载和采集!