java - Find Positions of Multiple Occurrences of a Character in a String -
if have string line = "xyztgexgxrx", line.indexof("x"); returns index of first "x" contained in string.
what want know, what allow me second "x", or occurrence of "x" after that?
answer can found here: java indexof method multiple matches in string
there second parameter indexof sets start parameter. code example prints indices of x
i = str.indexof('x'); while(i >= 0) { system.out.println(i); = str.indexof('x', i+1); }
Comments
Post a Comment