Duncan Jones created LANG-1037:
----------------------------------
Summary: Join list of objects with different end separator
Key: LANG-1037
URL: https://issues.apache.org/jira/browse/LANG-1037
Project: Commons Lang
Issue Type: New Feature
Components: lang.*
Reporter: Duncan Jones
Assignee: Duncan Jones
Priority: Minor
Fix For: Discussion
A common programming challenge is joining a list with a different separator
between the final two items. For example, joining a list with {{","}} as the
primary separator but {{"and"}} as the final separator.
I propose that we extend {{StringUtils}} with three additional methods:
{code:java}
public static String join(Iterable<?> iterable, String separator, String
endSeparator)
public static String join(Object[] array, String separator, String endSeparator)
public static String join(Object[] array, String separator, String
endSeparator, int startIndex, int endIndex)
{code}
This could also be added to the other {{join}} methods for primitives, but I
suspect the primary use case will be strings and I don't suggest we pollute the
class any further.
Below shows the expected pseudo output using {{","}} and {{"and"}}:
{code}
join(a) == a
join(a,b) == a and b
join(a,b,c) == a, b and c
{code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)