Conversation
There was a problem hiding this comment.
Pull request overview
Updates the HelloApp entrypoint to handle command-line arguments more flexibly by greeting all provided names instead of only the first one.
Changes:
- Inverts the argument check to explicitly handle the no-args case first (
args.length == 0). - Builds a comma-separated list from all command-line arguments and prints a combined greeting.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| StringBuilder nameBuilder = new StringBuilder(); | ||
| boolean first = true; | ||
|
|
||
| for (String name : args) { | ||
| if (!first) { | ||
| nameBuilder.append(", "); | ||
| } | ||
| nameBuilder.append(name); | ||
| first = false; | ||
| } | ||
|
|
||
| System.out.println("Hello, " + nameBuilder.toString() + "!"); |
There was a problem hiding this comment.
The manual StringBuilder + first flag loop is more verbose than necessary for joining arguments. Consider using String.join(", ", args) (if targeting Java 8+) to simplify and reduce branching.
| StringBuilder nameBuilder = new StringBuilder(); | |
| boolean first = true; | |
| for (String name : args) { | |
| if (!first) { | |
| nameBuilder.append(", "); | |
| } | |
| nameBuilder.append(name); | |
| first = false; | |
| } | |
| System.out.println("Hello, " + nameBuilder.toString() + "!"); | |
| String joinedNames = String.join(", ", args); | |
| System.out.println("Hello, " + joinedNames + "!"); |
| first = false; | ||
| } | ||
|
|
||
| System.out.println("Hello, " + nameBuilder.toString() + "!"); |
There was a problem hiding this comment.
nameBuilder.toString() is redundant here because string concatenation will call toString() implicitly. Using nameBuilder directly avoids the extra call and is a bit clearer.
| System.out.println("Hello, " + nameBuilder.toString() + "!"); | |
| System.out.println("Hello, " + nameBuilder + "!"); |
| } else { | ||
| StringBuilder nameBuilder = new StringBuilder(); | ||
| boolean first = true; | ||
|
|
There was a problem hiding this comment.
There appears to be trailing whitespace on this blank line; please remove it to keep diffs clean and avoid lint/formatting noise.
| nameBuilder.append(name); | ||
| first = false; | ||
| } | ||
|
|
There was a problem hiding this comment.
There appears to be trailing whitespace on this blank line; please remove it to keep diffs clean and avoid lint/formatting noise.
No description provided.