3 ms·
As others have said, stop fighting the language and embrace it. For the Java haters, here's a Java one-liner that is not much longer (though I'll admit, uglier
by zmimon 18y ago
As others have said, stop fighting the language and embrace it. For the Java haters, here's a Java one-liner that is not much longer (though I'll admit, uglier) than all the rest:
result = join(new ArrayList<String>(){{ addAll(list); while(remove("")); }},"\n");
And as a bonus - for the extra few characters you typed, this will fail at compile time instead of runtime when the list turns out to contain FooBars instead of strings.
- cgranade 18y agoMissing the application of Foo.description(). That said, I feel that compile-time failure is vastly underrated. Java is making even more progress on that front by introducing type checker frameworks with JSR 308.