Conversation
There was a problem hiding this comment.
Pull request overview
Refactors HelloApp greeting output to support greeting multiple provided names instead of only the first CLI argument.
Changes:
- Inverts the argument check to handle the
no-argscase first (Hello, World!). - Builds a comma-separated list of all CLI args and prints them in the greeting.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| for (String name : args) { | ||
| nameBuilder.append(name).append(", "); | ||
| } | ||
|
|
There was a problem hiding this comment.
There appears to be trailing whitespace on the blank lines in this block (e.g., the empty lines after new StringBuilder(); and after the loop). Please remove trailing spaces to avoid unnecessary diffs and potential style/lint failures.
| for (String name : args) { | |
| nameBuilder.append(name).append(", "); | |
| } | |
| for (String name : args) { | |
| nameBuilder.append(name).append(", "); | |
| } |
| StringBuilder nameBuilder = new StringBuilder(); | ||
|
|
||
| for (String name : args) { | ||
| nameBuilder.append(name).append(", "); | ||
| } | ||
|
|
||
| if (nameBuilder.length() > 0) { | ||
| String names = nameBuilder.substring(0, nameBuilder.length() - 2); | ||
| System.out.println("Hello, " + names + "!"); | ||
| } |
There was a problem hiding this comment.
In the else branch, if (nameBuilder.length() > 0) is redundant because this code path already implies args.length > 0. Also building with a trailing ", " then trimming via substring is harder to read and does extra work; consider String.join(", ", args) or StringJoiner to avoid the trim step.
| StringBuilder nameBuilder = new StringBuilder(); | |
| for (String name : args) { | |
| nameBuilder.append(name).append(", "); | |
| } | |
| if (nameBuilder.length() > 0) { | |
| String names = nameBuilder.substring(0, nameBuilder.length() - 2); | |
| System.out.println("Hello, " + names + "!"); | |
| } | |
| String names = String.join(", ", args); | |
| System.out.println("Hello, " + names + "!"); |
No description provided.