java - Splitting String based on occurance -


i want split string based on first occurrence when try use string.split("\_",1) - gives me arrayoutofbounds exception

array[0] = "this_first"; array[1] = "not_first"; array[2] = "maybe_like_this"; array[3] = "this_is_definitely_it";  for(int i=0;i<array.length;i++){         tmparr = array[i].split("\\_");         firstword = tmparr[0];         system.out.println(firstword);         tempstring = tmparr[1]; 

i want first word in tmparr[0] , rest in tmparr[1]. please advice

the limit parameter string#split(string, int) defined little bit strangely. go , read javadoc, particularly paragraph starting "the limit parameter...".

tl;dr: need this:

tmparr = array[i].split("_", 2); 

(backslash not required)


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -