Is it possible for split to return a null String[]? I am curious as I want to try to be as defensive as possible in my code without having unnecessary checks. The code is as follows:
String[] parts = myString.split("\\w");
do I need to perform a null check before I use parts post splitting?
It never returns null. You should always check the javadoc of the method if you are not sure. For example
String#split(String)says…and
String#split(String,int)says:From Javadoc you can also find out what kind of exceptions can happen and more importantly why were those exceptions thrown. Also one very important thing to check is if the classes are thread safe or not.