/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
class Test{
public static void main(String args[]){
String Str = new String("WelcometoTutorialspoint.com-");
int i=0;
System.out.println("Return Value :" );
for (String retval: Str.split("-", 2)){
System.out.println(retval);
System.out.println(i);
i++;
}
i=0;
System.out.println("");
System.out.println("Return Value :" );
for (String retval: Str.split("-", 3)){
System.out.println(retval);
System.out.println(i);
i++;
}
i=0;
System.out.println("");
System.out.println("Return Value :" );
for (String retval: Str.split("-", 0)){
System.out.println(retval);
System.out.println(i);
i++;
}
System.out.println("");
i=0;
System.out.println("Return Value :" );
for (String retval: Str.split("-")){
System.out.println(retval);
System.out.println(i);
i++;
}
}
}
In this, my delimiter is at the end. In last two cases , loop is running only for 1 time but in first 2 cases it is running for 2 times each. Why is it so??
Secondly, what is the measning of passing value zero to the second field of spilt function? Thanks.