1366 * this {@code String} object to be compared begins at index
1367 * {@code toffset} and has length {@code len}. The substring of
1368 * {@code other} to be compared begins at index {@code ooffset} and
1369 * has length {@code len}. The result is {@code false} if and only if
1370 * at least one of the following is true:
1371 * <ul><li>{@code toffset} is negative.
1372 * <li>{@code ooffset} is negative.
1373 * <li>{@code toffset+len} is greater than the length of this
1374 * {@code String} object.
1375 * <li>{@code ooffset+len} is greater than the length of the other
1376 * argument.
1377 * <li>{@code ignoreCase} is {@code false} and there is some nonnegative
1378 * integer <i>k</i> less than {@code len} such that:
1379 * <blockquote><pre>
1380 * this.charAt(toffset+k) != other.charAt(ooffset+k)
1381 * </pre></blockquote>
1382 * <li>{@code ignoreCase} is {@code true} and there is some nonnegative
1383 * integer <i>k</i> less than {@code len} such that:
1384 * <blockquote><pre>
1385 * Character.toLowerCase(Character.toUpperCase(this.charAt(toffset+k))) !=
1386 Character.toLowerCase(Character.toUpperCase(other.charAt(ooffset+k)))
1387 * </pre></blockquote>
1388 * </ul>
1389 *
1390 * <p>Note that this method does <em>not</em> take locale into account,
1391 * and will result in unsatisfactory results for certain locales when
1392 * {@code ignoreCase} is {@code true}. The {@link java.text.Collator} class
1393 * provides locale-sensitive comparison.
1394 *
1395 * @param ignoreCase if {@code true}, ignore case when comparing
1396 * characters.
1397 * @param toffset the starting offset of the subregion in this
1398 * string.
1399 * @param other the string argument.
1400 * @param ooffset the starting offset of the subregion in the string
1401 * argument.
1402 * @param len the number of characters to compare.
1403 * @return {@code true} if the specified subregion of this string
1404 * matches the specified subregion of the string argument;
1405 * {@code false} otherwise. Whether the matching is exact
1406 * or case insensitive depends on the {@code ignoreCase}
2428 public static String join(CharSequence delimiter, CharSequence... elements) {
2429 Objects.requireNonNull(delimiter);
2430 Objects.requireNonNull(elements);
2431 // Number of elements not likely worth Arrays.stream overhead.
2432 StringJoiner joiner = new StringJoiner(delimiter);
2433 for (CharSequence cs: elements) {
2434 joiner.add(cs);
2435 }
2436 return joiner.toString();
2437 }
2438
2439 /**
2440 * Returns a new {@code String} composed of copies of the
2441 * {@code CharSequence elements} joined together with a copy of the
2442 * specified {@code delimiter}.
2443 *
2444 * <blockquote>For example,
2445 * <pre>{@code
2446 * List<String> strings = List.of("Java", "is", "cool");
2447 * String message = String.join(" ", strings);
2448 * //message returned is: "Java is cool"
2449 *
2450 * Set<String> strings =
2451 * new LinkedHashSet<>(List.of("Java", "is", "very", "cool"));
2452 * String message = String.join("-", strings);
2453 * //message returned is: "Java-is-very-cool"
2454 * }</pre></blockquote>
2455 *
2456 * Note that if an individual element is {@code null}, then {@code "null"} is added.
2457 *
2458 * @param delimiter a sequence of characters that is used to separate each
2459 * of the {@code elements} in the resulting {@code String}
2460 * @param elements an {@code Iterable} that will have its {@code elements}
2461 * joined together.
2462 *
2463 * @return a new {@code String} that is composed from the {@code elements}
2464 * argument
2465 *
2466 * @throws NullPointerException If {@code delimiter} or {@code elements}
2467 * is {@code null}
2468 *
2469 * @see #join(CharSequence,CharSequence...)
2470 * @see java.util.StringJoiner
2471 * @since 1.8
2472 */
2473 public static String join(CharSequence delimiter,
|
1366 * this {@code String} object to be compared begins at index
1367 * {@code toffset} and has length {@code len}. The substring of
1368 * {@code other} to be compared begins at index {@code ooffset} and
1369 * has length {@code len}. The result is {@code false} if and only if
1370 * at least one of the following is true:
1371 * <ul><li>{@code toffset} is negative.
1372 * <li>{@code ooffset} is negative.
1373 * <li>{@code toffset+len} is greater than the length of this
1374 * {@code String} object.
1375 * <li>{@code ooffset+len} is greater than the length of the other
1376 * argument.
1377 * <li>{@code ignoreCase} is {@code false} and there is some nonnegative
1378 * integer <i>k</i> less than {@code len} such that:
1379 * <blockquote><pre>
1380 * this.charAt(toffset+k) != other.charAt(ooffset+k)
1381 * </pre></blockquote>
1382 * <li>{@code ignoreCase} is {@code true} and there is some nonnegative
1383 * integer <i>k</i> less than {@code len} such that:
1384 * <blockquote><pre>
1385 * Character.toLowerCase(Character.toUpperCase(this.charAt(toffset+k))) !=
1386 * Character.toLowerCase(Character.toUpperCase(other.charAt(ooffset+k)))
1387 * </pre></blockquote>
1388 * </ul>
1389 *
1390 * <p>Note that this method does <em>not</em> take locale into account,
1391 * and will result in unsatisfactory results for certain locales when
1392 * {@code ignoreCase} is {@code true}. The {@link java.text.Collator} class
1393 * provides locale-sensitive comparison.
1394 *
1395 * @param ignoreCase if {@code true}, ignore case when comparing
1396 * characters.
1397 * @param toffset the starting offset of the subregion in this
1398 * string.
1399 * @param other the string argument.
1400 * @param ooffset the starting offset of the subregion in the string
1401 * argument.
1402 * @param len the number of characters to compare.
1403 * @return {@code true} if the specified subregion of this string
1404 * matches the specified subregion of the string argument;
1405 * {@code false} otherwise. Whether the matching is exact
1406 * or case insensitive depends on the {@code ignoreCase}
2428 public static String join(CharSequence delimiter, CharSequence... elements) {
2429 Objects.requireNonNull(delimiter);
2430 Objects.requireNonNull(elements);
2431 // Number of elements not likely worth Arrays.stream overhead.
2432 StringJoiner joiner = new StringJoiner(delimiter);
2433 for (CharSequence cs: elements) {
2434 joiner.add(cs);
2435 }
2436 return joiner.toString();
2437 }
2438
2439 /**
2440 * Returns a new {@code String} composed of copies of the
2441 * {@code CharSequence elements} joined together with a copy of the
2442 * specified {@code delimiter}.
2443 *
2444 * <blockquote>For example,
2445 * <pre>{@code
2446 * List<String> strings = List.of("Java", "is", "cool");
2447 * String message = String.join(" ", strings);
2448 * // message returned is: "Java is cool"
2449 *
2450 * Set<String> strings =
2451 * new LinkedHashSet<>(List.of("Java", "is", "very", "cool"));
2452 * String message = String.join("-", strings);
2453 * // message returned is: "Java-is-very-cool"
2454 * }</pre></blockquote>
2455 *
2456 * Note that if an individual element is {@code null}, then {@code "null"} is added.
2457 *
2458 * @param delimiter a sequence of characters that is used to separate each
2459 * of the {@code elements} in the resulting {@code String}
2460 * @param elements an {@code Iterable} that will have its {@code elements}
2461 * joined together.
2462 *
2463 * @return a new {@code String} that is composed from the {@code elements}
2464 * argument
2465 *
2466 * @throws NullPointerException If {@code delimiter} or {@code elements}
2467 * is {@code null}
2468 *
2469 * @see #join(CharSequence,CharSequence...)
2470 * @see java.util.StringJoiner
2471 * @since 1.8
2472 */
2473 public static String join(CharSequence delimiter,
|