3 ms·
In Java we would use `String.format`. https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#format-java.lang.String-java.lang.Object...- https://docs
by vips7L 7y ago
In Java we would use `String.format`.
https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#format-java.lang.String-java.lang.Object...- https://docs.oracle.com/javase/8/docs/api/java/lang/String.h...
- Insanity 7y agoOh thanks :) I wasn't sure anymore about how I'd do it in Java so I wrote "a language that looks like Java". Took the easy way out instead of having to actually look it up. I'm going to leave it as it is though but good to know ;-)
- cozos 7y agoString.format is slow compared to normal string concatenation (i.e. "foo" + "bar")! Bit me once when using String.format in a hot path. https://stackoverflow.com/questions/513600/should-i-use-javas-string-format-if-performance-is-important https://stackoverflow.com/questions/513600/should-i-use-java...
- vips7L 7y agoThose benchmarks can't be accurate as they don't use JMH. Edit: i do believe you that + is faster, as it doesn't need to parse the format string, but you should still always do benchmarks with JMH or they won't be accurate.