Closed GoogleCodeExporter closed 9 years ago
Joiner.on(',').join(Collections.nCopies(10, "?"))
Original comment by kevinb@google.com
on 27 Jan 2011 at 1:22
Kevin, don't you think that "Joiner.on(',').join(Collections.nCopies(10, "?"))"
is too verbose?
Making a string of params separated by some delimiter is very common task and
special Strings.repeat() would be very helpful.
Original comment by kua...@gmail.com
on 27 Jan 2011 at 1:31
I often need to join collections / iterables containing various elements, but I
never encountered this use case. I can see how it could be useful for SQL
queries, but I believe Kevin is right here.
Sure [Joiner.on(',').join(Collections.nCopies(10, "?"))] is more verbose than
[Strings.repeat("?", 10, ",")], but it's also more powerful. For example, say
you actually want to append your repeated string to a StringBuilder. With
Joiner, you could do:
StringBuilder sb = ...
Joiner.on(',').appendTo(sb, nCopies(10, "?"));
Moreover, the [Strings.repeat(String str, int count, String separator)] method
is risky: people might unknowingly invert the "str" and "separator" arguments.
Original comment by nev...@gmail.com
on 28 Jan 2011 at 11:29
Not implementing such a shortcut might also additionally motivate to replace
risky manual SQL query assembly ;)
Original comment by j...@nwsnet.de
on 31 Jan 2011 at 8:52
This issue has been migrated to GitHub.
It can be found at https://github.com/google/guava/issues/<id>
Original comment by cgdecker@google.com
on 1 Nov 2014 at 4:15
Original comment by cgdecker@google.com
on 3 Nov 2014 at 9:09
Original issue reported on code.google.com by
wrom...@gmail.com
on 27 Jan 2011 at 12:59