Convert a List into an Array with Strings

I always have to look this up 🙁 hence I take down here a note:

list.toArray(new String[list.size()]);

This converts an List, e.g. ArrayList to an Array with Strings. Of course the objects in the list must be Strings.

About Lars Vogel

Lars Vogel is the founder and CEO of the vogella GmbH and works as Eclipse and Android consultant, trainer and book author. He is a regular speaker at international conferences, He is the primary author of With more than one million visitors per month this website is one of the central sources for Java, Eclipse and Android programming information.
This entry was posted in Uncategorized. Bookmark the permalink.