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

List

Fill in the bkank to declare the rocks variable as a list that contain rocks

1 Answer

Tonnie Fanadez
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Tonnie Fanadez
UX Design Techdegree Graduate 22,796 Points

Hi Rumbidzai Rutendo Nhopi Nyikadzinashe - quite a name there.

List represents an ordered sequence of objects; since List is an interface, you need to instantiate a concrete implementation of the interface in order to use it. The most common implementation is ArrayList which I have used below. Other implementations of List Interface are LinkedList and Vector

List<Rock> rocks = new ArrayList<>();

So you need to declare a List of type Rock (put this inside the diamond brackets) - I have called mine just rocks and then instantiated the list to a new ArrayList. I have left the diamond brackets on the Right side empty because the compiler will infer it as Rock type so you don't have to worry or specify the type on the Right side.