Skip to content

Commit

Permalink
Simplified Strings::join(String, List<Object>)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkarg committed Aug 9, 2024
1 parent e5c4772 commit 7c42947
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/main/java/com/beust/jcommander/Strings.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.beust.jcommander;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Strings {

Expand All @@ -21,14 +23,6 @@ public static String join(String delimiter, List<String> args) {
}

public static String join(String delimiter, Object[] args) {
StringBuilder builder = new StringBuilder();

for (int i = 0; i < args.length; i++) {
builder.append(args[i]);

if (i + 1 < args.length)
builder.append(delimiter);
}
return builder.toString();
return Arrays.stream(args).map(String::valueOf).collect(Collectors.joining(delimiter));
}
}

0 comments on commit 7c42947

Please sign in to comment.