Can somebody check the code below and explain the second case ?
public class SplitMain {
public static void main(String[] args) {
String[] arr = {"", "/", "as/d"};
for (String s : arr){
System.out.println(" Output : " + printStrArr(s.split("/")));
}
}
public static String printStrArr(String[] ar){
String out = "";
System.out.println("Length = " + ar.length);
for (String s1 : ar){
out += (s1 + "--");
}
return out;
}
}
Result ::
Length = 1 Output : --
Length = 0 Output :
Length = 2 Output : as--d--
When the input is just "", the output length is 1, which makes sense; the thirdcase is the normal case; but the second case, when input is "/", the result array is of length 0. Why is that ?