wells101/PSET1

Use StringBuilder

Opened this issue · 1 comments

Hey Adam,

Great looking code. Nice job with the first pset.

My biggest recommendation would be to watch the videos about String again.
http://tv.launchcode.us/#/videos/java_strings_performance?lesson=Java

Since Strings are immutable, string1 + string2 = string3... we end up with three strings total. For a small application like this it's not bad, but what if your pyramid was 1,000,000 levels high; that would lead to a lot of wasted String objects and garbage collection. So use StringBuilder. It helps with that.

Cheers,
Mike

Actually, i'm goign to correct myself and probably disagree with you Mike.

To my knowledge, printing to the console isn't creating string objects, since i'm using literals instead. Now, if this isn't the case (entirely possible!) the solution to reducing the number of objects created is to go to character literals inside the printn methods. this eliminates all objects entirely, as I've now used primitives instead (okay, technically objects, but much more memory-friendly!)