Moudiz Moudiz - 5 months ago 9
Java Question

get count of string with commas and split them

I am new to java . I have this String.

str="plane,cat,red,dogy";


I want to make a loop and send the data . the below is wrong but i want something similar to it.

for ( int i = 0; i>str.length; i++)
{
str=split.string(,);
// i know it wrong but I want to get the result before comma, for example first loop plane, second loop cat third loop red and so on
updatestatement(str);
}

Answer

This should be what you are looking for:

String str="plane,cat,red,dogy";
for(String subString: str.split(",")){
   updatestatement(subString);
}