According to the String.split()
documentation the method returns array, so how come the following code compiles?
The retval
variable inside the for loop is a String
and not an array but there is no error?
public class String_Splitting_Example
{
public static void main(String args[])
{
String Str = new String("Welcome-to-Tutorialspoint.com");
System.out.println("");
System.out.println("Return Value :" );
for (String retval: Str.split("-"))
{
System.out.println(retval);
}
}
}