dcsimg
LinkedIn
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Tip: Converting a Java List to an array

How to convert a Java List to an array.


advertisement

Converting a Java List an array can be done like this:

Foo[] arr = givenList.toArray(new Foo[0]);

Or, like this:

Foo[] arr = new Foo[givenList.size()];
givenList.toArray(arr); 

Or, in functional style:

Foo[] arr = givenList.stream().toArray(Foo[]::new);

Foo[] arr = givenList.toArray(Foo[]::new);


   
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date