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

Android Build a Simple Android App (retired 2014) Learning the Language Introduction to Arrays

Jacqueline Steremberg
Jacqueline Steremberg
2,376 Points

Is it really necessary to add a newline for each array element?

I lost a lot of time looking for my error and the problem was i declared all the elements on the same line. Is it really wrong?

Luke O'Neill
Luke O'Neill
7,822 Points

You were probably getting the error because of how treehouse checks your code. Alessandro hit the nail on the head though, you don't need new lines.

2 Answers

Alessandro Calorì
Alessandro Calorì
10,241 Points

Java does not care about newlines. You could theorically write all of your code on a single line. The imporant thing is that the syntax of the code is correct.

int[] numbers = { 1, 2, 3, 4 };

have the same meaning of:

int[] numbers =
{
   1,
   2,
   3,
   4
};

Watch out for semicolumns and columns: those are ESSENTIAL.

Jacqueline Steremberg
Jacqueline Steremberg
2,376 Points

I thought so! Thank you very much for your replies!