Return-Path: X-Original-To: apmail-commons-issues-archive@minotaur.apache.org Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A001F1185C for ; Wed, 10 Sep 2014 09:27:41 +0000 (UTC) Received: (qmail 40293 invoked by uid 500); 10 Sep 2014 09:27:28 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 40196 invoked by uid 500); 10 Sep 2014 09:27:28 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 40184 invoked by uid 99); 10 Sep 2014 09:27:28 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 10 Sep 2014 09:27:28 +0000 Date: Wed, 10 Sep 2014 09:27:28 +0000 (UTC) From: "Duncan Jones (JIRA)" To: issues@commons.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (LANG-1037) Join list of objects with different end separator MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/LANG-1037?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Duncan Jones updated LANG-1037: ------------------------------- Description: 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} Take a look at [this Stack Overflow question|http://stackoverflow.com/q/8255077/474189] to see just how awkward the current solutions are: was: 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} > 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} > Take a look at [this Stack Overflow question|http://stackoverflow.com/q/8255077/474189] to see just how awkward the current solutions are: -- This message was sent by Atlassian JIRA (v6.3.4#6332)