Categories
functions java

JAVA:Splitting a String

In java you can split a string into two strings based on the delimeter using function split().
Example Given below

String s1 = “You are a dog”;
String[] pieces = s1.split(” “);

here we are splitting the string with ” ” (single space) as delimiter. The result will be a array of strings.. like

pieces[0] = You
pieces[1] = are
pieces[2] = a
pieces[3] = dog