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 Organizing Data Arrays

Kevin Faust
Kevin Faust
15,353 Points

hmm so which array is the best one?

So craig explained 3 different ways to add stuff to an array. For me, the easiest way is just using the copyOf() method as its the most simple and clean. I have added the other 2 ways but they look so messy and bothersome. Will there be cases where I would have to use them or can I just use copyOf() all the time?

or is it just more of a know-how-each-works but just use whichever you like most

2 Answers

Of the solutions presented in this lecture, copyOf seems to be the best way "always". It looks the cleanest and requires the least code (and the least use of crazy old code that doesn't even follow "current" naming conventions).

I'm really hoping that Craig shows us an additional "better way" in the upcoming lectures though. Two instructions to add each item to an array seems pretty wasteful and messy to me.

Kevin Faust
Kevin Faust
15,353 Points

lol i forgot that i even wrote this. to be honest i rarely if ever have used the copyOf() method. you'll mostly be using arrays if you have a fixed length of data or more commonly use lists which you'll be introduced to later if you havent learned it yet

Yep, lol, I've progressed further in the course now myself ... lists are so much more practical :)