Split the String in java

 Split the String in java using split method.
public class StringSplitExample {
public static void main(String[] args) {
String str = “India,America,China,England”;

String[] namesOfArray = str.split(“,”);

System.out.println(“Names are: “);

for (String name : namesOfArray)
{

System.out.println(name);

}

}

}
/*
Output:
Names are:
India
America
China
England

*/

Leave a Reply

Your email address will not be published. Required fields are marked *

11 + = 18