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

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -