Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Objects Creating the MVP Current Progress

Chris Rubio
Chris Rubio
1,643 Points

question ...ok on the video CURRENT PROGRESS min 4:48 --he said String progress = ""; could he have done = null instead

question ...ok on the video CURRENT PROGRESS min 4:48 --he said String progress = ""; could he have done = null instead of the quotations ?

1 Answer

Ben Reynolds
Ben Reynolds
35,170 Points

No, because later in the method he starts concatenating values to the progress string and needed a blank starting point. An empty string is still a string, that is an instance of the String class, even if it doesn't have any characters assigned to it yet.

Null on the other hand is not, and if you try to concatenate to it, it will first convert that null to the word "null". When I tested in JShell I got this:

String a = null;
a += "test";
// resulting value of a was "nulltest"