android: Can method Split return a null value? -


i problem when reading code.

why coder determine allprovinces = null?

if(!textutils.isempty(response)){     string [] allprovinces = response.split(",");     /* how should check whether allprovinces null or not?       * means method "split" can possibly return null value?      */     if( allprovinces != null && allprovinces.length > 0){             for(string p :allprovinces) {             string [] array = p.split("//|");             province province = new province();             province.setprovincename(array [0]);             province.setprovincecode(array[1]);             weatherdb.saveprovince(province);         }     } } 

can method split return null value?

split function return string[] containing @ least 1 element.

you array of size 1 holding original value:

split method character "-"

input          output -----          ------ abcd-xyz      {"abcd", "xyz"} qwert         {"qwert"} zxc-q-        {"zxc","q"} zxc-q- -      {"zxc","q",""} 

why coder determine allprovinces =null

it's useless check null because split function return string[] containing @ least 1 element.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -