Java toArray() method directly for Primitive Data Type.
How to use same method for String or Other Custom class list efficiently ?
Here is the simple solution.
Just pass the array Object with required size as a parameter to toArray();
Code snippet for String:
List <String> names = …..
……..
…….
names.toArray(new String [names.size()]);
Code snippet for Custom Class:
List<CustomClass> objects = ….
…………
………
objects.toArray(new CustomClass[objects.size()]);
Thanks for referring Techiehints.

Leave a comment