Last active
August 27, 2019 15:28
-
-
Save yavuztas/aac21ba0aeafa5e51cfd04b10cec613b to your computer and use it in GitHub Desktop.
Created with Copy to Gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static <T> String join(T[] array, String separator) { | |
return UtilsForCollections.join(array, separator, 0); | |
} | |
public static <T> String join(T[] array, String separator, int limit) { | |
if (limit > 0 && array.length > limit) { | |
return Arrays.stream(array) | |
.limit(limit) | |
.map(String::valueOf) | |
.collect(Collectors.joining(separator)) + separator + "..."; | |
} | |
return Arrays.stream(array).map(String::valueOf) | |
.collect(Collectors.joining(separator)); | |
} | |
public static <T> String join(Collection<T> collection, String separator) { | |
return UtilsForCollections.join(collection, separator, 0); | |
} | |
public static <T> String join(Collection<T> collection, String separator, int limit) { | |
if (limit > 0 && collection.size() > limit) { | |
return collection.stream() | |
.limit(limit) | |
.map(String::valueOf) | |
.collect(Collectors.joining(separator)) + separator + "..."; | |
} | |
return collection.stream().map(String::valueOf) | |
.collect(Collectors.joining(separator)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment