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!

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 Efficiency! Queueing

Manh Truong Nguyen
Manh Truong Nguyen
2,021 Points

i dont understanding this line of code plz help

in this video at 10:51 he wrote List<String> artists = new ArrayList<>(mSongBook.getArtists()); i dont understanding why he puts mSongBook.getArtists() in that bracket of Arraylist? cuz normally he just left it blank

2 Answers

Brendon Butler
Brendon Butler
4,254 Points

Erik was correct. You can create an empty list by leaving it blank and adding in values later.

If you already have some sort of Collections that contains data, you can input that into the parenthesis to fill your new list.

Erik Gabor
Erik Gabor
6,427 Points

It really reminds me of C# generics

List<int> numbers =new List<int>();

I don't know Java. But my hunch is it inializes a list of strings