Repository: commons-lang Updated Branches: refs/heads/master 05647d46e -> 8d601ab71
LANG-1258: Add ArrayUtils#toStringArray(Object[]) method patch supplied by IG Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/8d95ae41 Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/8d95ae41 Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/8d95ae41 Branch: refs/heads/master Commit: 8d95ae41975a2307501aa0f4a7eba296c59edce9 Parents: 05647d4 Author: mildis <igard...@yahoo.fr> Authored: Tue Aug 16 18:00:00 2016 +0200 Committer: pascalschumacher <pascalschumac...@gmx.net> Committed: Sun Nov 13 16:59:56 2016 +0100 ---------------------------------------------------------------------- .../org/apache/commons/lang3/ArrayUtils.java | 23 ++++++++++++++++++++ .../apache/commons/lang3/ArrayUtilsTest.java | 8 +++++++ 2 files changed, 31 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-lang/blob/8d95ae41/src/main/java/org/apache/commons/lang3/ArrayUtils.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/lang3/ArrayUtils.java b/src/main/java/org/apache/commons/lang3/ArrayUtils.java index f8ae695..8c1108e 100644 --- a/src/main/java/org/apache/commons/lang3/ArrayUtils.java +++ b/src/main/java/org/apache/commons/lang3/ArrayUtils.java @@ -7968,4 +7968,27 @@ public class ArrayUtils { return removeAll(array, Arrays.copyOf(indices, count)); } + + /** + * Returns an array containing the string representation of each entry in the argument array. + * + * <p> + * A {@code null} input Object[] returns {@code null}. + * </p> + * + * @param source the Object[] to be processed, may be null + * @return String[] of the same size as the source with its element's string representation, + * {@code null} if null Object[] input + * @since 3.6 + */ + public static String[] toStringArray(final Object[] source) { + if (null == source) return null; + + String[] al = new String[source.length]; + for (int i = 0; i < source.length; i++) { + al[i] = source[i].toString(); + } + + return al; + } } http://git-wip-us.apache.org/repos/asf/commons-lang/blob/8d95ae41/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java b/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java index 0cb5530..da639b5 100644 --- a/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java @@ -4442,4 +4442,12 @@ public class ArrayUtilsTest { Assert.assertArrayEquals(new double[]{2.718}, (double[]) ArrayUtils.toPrimitive(new Double[]{2.718}), 0.1); } + @Test + public void testToStringArray() { + assertNull(ArrayUtils.toStringArray(null)); + + final Object[] array = new Object[] {1, 2, 3, "array", "test"}; + assertArrayEquals(new String[]{"1", "2", "3", "array", "test"}, ArrayUtils.toStringArray(array)); + } + }