split string in java
Java equivalent of PHP explode function In PHP we can easily break a long string into smaller parts by using the explode() function of PHP. $longstring="I am a cool guy " ; $brokenstring=explode(" ", $longstring); After the execution of the second command the variable $brokenstring is an array such that, $brokenstring[0]="I" $brokenstring[1]="am" $brokenstring[2]="a" $brokenstring[3]="cool" $brokenstring[4]="guy" In java we use String.split() function that achieves the same objective. class splitString { public static void main(String[] args) { String s1 = " I am a cool guy "; String[] array = s1.split(" "); for(int i=0; i ...