Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Data Structures Exploring the Java Collection Framework Lists

Can anyone explain? How did Craig use it to explain in the video?

1 -.toArray (new String [0])

2- Arrays.asList()

Steven Parker Brendan Whiting Gavin Ralston Gabbie Metheny

1 Answer

  1. He was showing that if you have a List of Strings you can use the toArray() method to generate an array of Strings. Using toArray() with no arguments produces an Object which is an array of Strings. If you need an actual String array, you can pass the toArray() method an argument which is a String array (Craig just created a new one inline with new String[0]).
  2. Working the other way, Craig was showing that if we have some Strings (or any Objects of the same type) that we want to convert into a List of Strings (or a List of Objects of the same type), we can use the Arrays.asList() method. Just pass the objects as a comma-separated list of arguments.