Split a String in controlled manner

You must have used String’s split method a lot of time to split based on a regex or a simple character or sub-string. But did you know that you can apply the split function in controlled manner. i.e. you can specify how many time split should occur or number of max sub-strings you can expect.

Example if I have string boo:and:foo and I will control number of splits to 2 like str.split(“:”,2), I will get 2 substrings, “boo” and “and:foo”.

Read more – http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#split%28java.lang.String,%20int%29