java - Split method of String class returns a string? -
according string.split() documentation method returns array, how come following code compiles?
the retval variable inside loop string , not array there 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 :" ); (string retval: str.split("-")) { system.out.println(retval); } } }
as jared burrows commented, writing for (string retval: str.split("-")) iterating through each part of array retval contains current string in array of strings got doing str.split
Comments
Post a Comment