Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
String s = a.stream()
.map(x -> {
if (!x.contains(" ")) return x;
return q + x + q;
})
.reduce((x, y) -> x + d + y)
.get();
import static java.lang.String.join;
import static java.lang.String.valueOf;
import java.util.ArrayList;
import java.util.List;
class X extends ArrayList<String> {
char d, q;
X(char d, char q) {
this.d = d;
this.q = q;
}
@Override
public boolean add(String s) {
if (s.contains(" ")) s = q + s + q;
return super.add(s);
}
@Override
public String toString() {
return join(valueOf(d), this);
}
}
X x = new X(d, q);
a.forEach(x::add);
String s = x.toString();
s = a.map{_1.include?(" ") ? q + _1 + q : _1 }.join(d)