How to split a String using split function
This tip will show the use of split function to split a String according to particular separator character.
In this program Split() function is splitting the String according to ‘:’ .
Code:
public class StringSplit {
public void doit() {
String str = "CompChamps:Guys:are:There";
String [] temp = null;
temp = str.split(":");
dump(temp);
}
public void dump(String []s) {
for (int i = 0 ; i < s.length ; i++) {
System.out.println(s[i]);
}
}
}
public static void main(String args[]) throws Exception{
StringSplit ss = new StringSplit();
ss.doit();
}