Hello,

The String.join javadoc contains some sample code to demonstrate how to use the method. The sample code can be improved with the new-in-JDK-9 List convenience factory method. Please review this patch to update the sample code:

--- a/src/java.base/share/classes/java/lang/String.java Tue May 31 17:54:41 2016 -0700 +++ b/src/java.base/share/classes/java/lang/String.java Tue May 31 18:27:45 2016 -0700
@@ -2424,9 +2424,7 @@
      *
      * <blockquote>For example,
      * <pre>{@code
-     *     List<String> strings = new LinkedList<>();
-     *     strings.add("Java");strings.add("is");
-     *     strings.add("cool");
+     *     List<String> strings = List.of("Java", "is", "cool");
      *     String message = String.join(" ", strings);
      *     //message returned is: "Java is cool"
      *

(A corresponding update should *not* be made to the String.join sample using a Set since the Set convenience factory methods do not guarantee ordering.)

Thanks,

-Joe

Reply via email to