Here is the current code in my application:
String[] ids = str.split("/");
When profiling the application, a non-negligeable time is spent string splitting. Also, the split method takes a regular expression, which is superfluous here.
What alternative can I use in order to optimize the string splitting? Is StringUtils.split faster?
(I would’ve tried and tested myself but profiling my application takes a lot of time.)
String.split(String)won’t create regexp if your pattern is only one character long. When splitting by single character, it will use specialized code which is pretty efficient.StringTokenizeris not much faster in this particular case.This was introduced in OpenJDK7/OracleJDK7. Here’s a bug report and a commit. I’ve made a simple benchmark here.