Let's look at the implementation Arrays.toString:
public static String toString(Object[] a) {
if (a == null)
return "null";
int iMax = a.length - 1;
if (iMax == -1)
return "[]";
StringBuilder b = new StringBuilder();
b.append('[');
for (int i = 0; ; i++) {
b.append(String.valueOf(a[i]));
if (i == iMax)
return b.append(']').toString();
b.append(", ");
}
}
Now, since the array is not empty, we move on to the loop for. Let's start by adding [to the result. Then add String.valueOf(a[i]). Try to print it:
String str = "";
String[] arr = str.split("\\s+");
System.out.println(String.valueOf(arr[0]));
You will see that the conclusion ... nothing! So the end result:
[]
, Java 8. split .