提交 5582e321 编写于 作者: P psandoz

8014383: StringJoiner example in class description not in sync with streams API

Reviewed-by: alanb
上级 416ce3a8
...@@ -29,14 +29,6 @@ package java.util; ...@@ -29,14 +29,6 @@ package java.util;
* by a delimiter and optionally starting with a supplied prefix * by a delimiter and optionally starting with a supplied prefix
* and ending with a supplied suffix. * and ending with a supplied suffix.
* <p> * <p>
* For example, the String {@code "[George:Sally:Fred]"} may
* be constructed as follows:
* <pre> {@code
* StringJoiner sj = new StringJoiner(":", "[", "]");
* sj.add("George").add("Sally").add("Fred");
* String desiredString = sj.toString();
* }</pre>
* <p>
* Prior to adding something to the {@code StringJoiner}, its * Prior to adding something to the {@code StringJoiner}, its
* {@code sj.toString()} method will, by default, return {@code prefix + suffix}. * {@code sj.toString()} method will, by default, return {@code prefix + suffix}.
* However, if the {@code setEmptyValue} method is called, the {@code emptyValue} * However, if the {@code setEmptyValue} method is called, the {@code emptyValue}
...@@ -45,17 +37,28 @@ package java.util; ...@@ -45,17 +37,28 @@ package java.util;
* <code>"{}"</code>, where the {@code prefix} is <code>"{"</code>, the * <code>"{}"</code>, where the {@code prefix} is <code>"{"</code>, the
* {@code suffix} is <code>"}"</code> and nothing has been added to the * {@code suffix} is <code>"}"</code> and nothing has been added to the
* {@code StringJoiner}. * {@code StringJoiner}.
*
* @apiNote
* <p>The String {@code "[George:Sally:Fred]"} may be constructed as follows:
*
* <pre> {@code
* StringJoiner sj = new StringJoiner(":", "[", "]");
* sj.add("George").add("Sally").add("Fred");
* String desiredString = sj.toString();
* }</pre>
* <p> * <p>
* A {@code StringJoiner} may be employed to create formatted output from a * A {@code StringJoiner} may be employed to create formatted output from a
* collection using lambda expressions as shown in the following example. * {@link java.util.stream.Stream} using
* {@link java.util.stream.Collectors#toStringJoiner}. For example:
* *
* <pre> {@code * <pre> {@code
* List<Person> people = ... * List<Integer> numbers = Arrays.asList(1, 2, 3, 4);
* String commaSeparatedNames = * String commaSeparatedNumbers = numbers.stream()
* people.map(p -> p.getName()).into(new StringJoiner(", ")).toString(); * .map(i -> i.toString())
* .collect(Collectors.toStringJoiner(", ")).toString();
* }</pre> * }</pre>
* *
* @author Jim Gish * @see java.util.stream.Collectors#toStringJoiner
* @since 1.8 * @since 1.8
*/ */
public final class StringJoiner { public final class StringJoiner {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册