Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
2erXre525046yjust a guess: substring is deleting the last one character from the last "city" as well
-
lumy3576yWoaaaah so much complicated for just:
','. Join(cities)
... Dear java you run on more than 3 billions hardwares, but you're still so uncomfortable to dev with! -
for-Each5396y@lumy The problem in this instance isn't Java. It's the developer.
You can do the exact same thing in under five lines of code. -
@for-Each It definitely is busier then it should be. Too much dependence on for loops will get you in trouble quickly.
-
Let me have a stab at what I consider wrong here. Please feel free to correct me on any of the points or add more to it :)
0. Method name (10pts to @Skayo)
1. No JavaDocs (sorry, I'm a stickler)
2. Clearly copied someone's sample that concatenates cities and didn't even bother to generify the "city" variable
3. StringBuilder is a FUCKING builder, why not use it as such: builder.append(city).append(delimiter)
4. Annotating method args with @NonNull in util methods and then bubbling up NPEs is just lazy. Own your fucking code!!!
5. Any reason for not using TextUtils.join() from Android API (since API 1) or Arrays.join() from Java8? Or Kotlin Array.joinToString()?
Related Rants
So, this is apparently how you concatenate a list of Strings or should I say cities π (with a delimiter between each element but excluding the last one)
I wish my esteemed colleague at least had decency to hide the fact he copied it from SO π
Question: what's wrong with this codeβ
devrant
java
wtf?
haxx0r
questions
expert