[lang] org.apache.commons.lang3.StringUtils.join(Object[], char) backward

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[lang] org.apache.commons.lang3.StringUtils.join(Object[], char) backward

garydgregory
HI All:

Now that Java's had varargs for a while now, using APIs like
org.apache.commons.lang3.StringUtils.join(Object[], char) feels backward to
me. I want to say:

StringUtils.join('.', "foo", "bar", "bang");

Not:

StringUtils.join(new String[] { "foo", "bar", "bang" }, '.');

Any thoughts on deprecating the former for the latter (which would be a new
API)?

Gary
Reply | Threaded
Open this post in threaded view
|

Re: [lang] org.apache.commons.lang3.StringUtils.join(Object[], char) backward

Matt Benson-2
Definitely +1 if we didn't already do this, except I would put what I call
a "Yoda preposition" in there, e.g. joinBy or joinWith.

Matt

On Wed, Mar 11, 2020, 9:00 AM Gary Gregory <[hidden email]> wrote:

> HI All:
>
> Now that Java's had varargs for a while now, using APIs like
> org.apache.commons.lang3.StringUtils.join(Object[], char) feels backward to
> me. I want to say:
>
> StringUtils.join('.', "foo", "bar", "bang");
>
> Not:
>
> StringUtils.join(new String[] { "foo", "bar", "bang" }, '.');
>
> Any thoughts on deprecating the former for the latter (which would be a new
> API)?
>
> Gary
>
Reply | Threaded
Open this post in threaded view
|

Re: [lang] org.apache.commons.lang3.StringUtils.join(Object[], char) backward

Tomo Suzuki
(I'm not a commons-lang user)
Java 8 has String.join for the same purpose.
https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#join-java.lang.CharSequence-java.lang.CharSequence...-
I would deprecate StringUtils.join in favor of String.join.

On Wed, Mar 11, 2020 at 10:16 AM Matt Benson <[hidden email]> wrote:

> Definitely +1 if we didn't already do this, except I would put what I call
> a "Yoda preposition" in there, e.g. joinBy or joinWith.
>
> Matt
>
> On Wed, Mar 11, 2020, 9:00 AM Gary Gregory <[hidden email]> wrote:
>
> > HI All:
> >
> > Now that Java's had varargs for a while now, using APIs like
> > org.apache.commons.lang3.StringUtils.join(Object[], char) feels backward
> to
> > me. I want to say:
> >
> > StringUtils.join('.', "foo", "bar", "bang");
> >
> > Not:
> >
> > StringUtils.join(new String[] { "foo", "bar", "bang" }, '.');
> >
> > Any thoughts on deprecating the former for the latter (which would be a
> new
> > API)?
> >
> > Gary
> >
>


--
Regards,
Tomo
Reply | Threaded
Open this post in threaded view
|

Re: [lang] org.apache.commons.lang3.StringUtils.join(Object[], char) backward

garydgregory
On Wed, Mar 11, 2020 at 10:24 AM Tomo Suzuki <[hidden email]>
wrote:

> (I'm not a commons-lang user)
> Java 8 has String.join for the same purpose.
>
> https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#join-java.lang.CharSequence-java.lang.CharSequence...-
> I would deprecate StringUtils.join in favor of String.join.
>

How would that work when StringUtils.join works with Object input and
String.join uses CharSequence?

Would you convert all Objects to Strings in a new array and then call
String.join? Seem like it could be painful to create a new array for each
call.

Gary


> On Wed, Mar 11, 2020 at 10:16 AM Matt Benson <[hidden email]> wrote:
>
> > Definitely +1 if we didn't already do this, except I would put what I
> call
> > a "Yoda preposition" in there, e.g. joinBy or joinWith.
> >
> > Matt
> >
> > On Wed, Mar 11, 2020, 9:00 AM Gary Gregory <[hidden email]>
> wrote:
> >
> > > HI All:
> > >
> > > Now that Java's had varargs for a while now, using APIs like
> > > org.apache.commons.lang3.StringUtils.join(Object[], char) feels
> backward
> > to
> > > me. I want to say:
> > >
> > > StringUtils.join('.', "foo", "bar", "bang");
> > >
> > > Not:
> > >
> > > StringUtils.join(new String[] { "foo", "bar", "bang" }, '.');
> > >
> > > Any thoughts on deprecating the former for the latter (which would be a
> > new
> > > API)?
> > >
> > > Gary
> > >
> >
>
>
> --
> Regards,
> Tomo
>
Reply | Threaded
Open this post in threaded view
|

Re: [lang] org.apache.commons.lang3.StringUtils.join(Object[], char) backward

Tomo Suzuki
Gary,

That's a good point. I wasn't thinking about StringUtil's applicability to
Object array.

On Wed, Mar 11, 2020 at 11:18 AM Gary Gregory <[hidden email]>
wrote:

> On Wed, Mar 11, 2020 at 10:24 AM Tomo Suzuki <[hidden email]>
> wrote:
>
> > (I'm not a commons-lang user)
> > Java 8 has String.join for the same purpose.
> >
> >
> https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#join-java.lang.CharSequence-java.lang.CharSequence...-
> > I would deprecate StringUtils.join in favor of String.join.
> >
>
> How would that work when StringUtils.join works with Object input and
> String.join uses CharSequence?
>
> Would you convert all Objects to Strings in a new array and then call
> String.join? Seem like it could be painful to create a new array for each
> call.
>
> Gary
>
>
> > On Wed, Mar 11, 2020 at 10:16 AM Matt Benson <[hidden email]>
> wrote:
> >
> > > Definitely +1 if we didn't already do this, except I would put what I
> > call
> > > a "Yoda preposition" in there, e.g. joinBy or joinWith.
> > >
> > > Matt
> > >
> > > On Wed, Mar 11, 2020, 9:00 AM Gary Gregory <[hidden email]>
> > wrote:
> > >
> > > > HI All:
> > > >
> > > > Now that Java's had varargs for a while now, using APIs like
> > > > org.apache.commons.lang3.StringUtils.join(Object[], char) feels
> > backward
> > > to
> > > > me. I want to say:
> > > >
> > > > StringUtils.join('.', "foo", "bar", "bang");
> > > >
> > > > Not:
> > > >
> > > > StringUtils.join(new String[] { "foo", "bar", "bang" }, '.');
> > > >
> > > > Any thoughts on deprecating the former for the latter (which would
> be a
> > > new
> > > > API)?
> > > >
> > > > Gary
> > > >
> > >
> >
> >
> > --
> > Regards,
> > Tomo
> >
>


--
Regards,
Tomo
Reply | Threaded
Open this post in threaded view
|

Re: [lang] org.apache.commons.lang3.StringUtils.join(Object[], char) backward

Rob Spoor
Apparently you guys forgot about joinWith:
https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringUtils.html#joinWith-java.lang.String-java.lang.Object...-

However, even without this method, StringUtils.join can easily be
replaced with streams:

     Stream.of(x, y, z).collect(joining("."));



On 11/03/2020 16:33, Tomo Suzuki wrote:

> Gary,
>
> That's a good point. I wasn't thinking about StringUtil's applicability to
> Object array.
>
> On Wed, Mar 11, 2020 at 11:18 AM Gary Gregory <[hidden email]>
> wrote:
>
>> On Wed, Mar 11, 2020 at 10:24 AM Tomo Suzuki <[hidden email]>
>> wrote:
>>
>>> (I'm not a commons-lang user)
>>> Java 8 has String.join for the same purpose.
>>>
>>>
>> https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#join-java.lang.CharSequence-java.lang.CharSequence...-
>>> I would deprecate StringUtils.join in favor of String.join.
>>>
>>
>> How would that work when StringUtils.join works with Object input and
>> String.join uses CharSequence?
>>
>> Would you convert all Objects to Strings in a new array and then call
>> String.join? Seem like it could be painful to create a new array for each
>> call.
>>
>> Gary
>>
>>
>>> On Wed, Mar 11, 2020 at 10:16 AM Matt Benson <[hidden email]>
>> wrote:
>>>
>>>> Definitely +1 if we didn't already do this, except I would put what I
>>> call
>>>> a "Yoda preposition" in there, e.g. joinBy or joinWith.
>>>>
>>>> Matt
>>>>
>>>> On Wed, Mar 11, 2020, 9:00 AM Gary Gregory <[hidden email]>
>>> wrote:
>>>>
>>>>> HI All:
>>>>>
>>>>> Now that Java's had varargs for a while now, using APIs like
>>>>> org.apache.commons.lang3.StringUtils.join(Object[], char) feels
>>> backward
>>>> to
>>>>> me. I want to say:
>>>>>
>>>>> StringUtils.join('.', "foo", "bar", "bang");
>>>>>
>>>>> Not:
>>>>>
>>>>> StringUtils.join(new String[] { "foo", "bar", "bang" }, '.');
>>>>>
>>>>> Any thoughts on deprecating the former for the latter (which would
>> be a
>>>> new
>>>>> API)?
>>>>>
>>>>> Gary
>>>>>
>>>>
>>>
>>>
>>> --
>>> Regards,
>>> Tomo

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]