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

Popular posts from this blog

android - How to save instance state of selected radiobutton on menu -

python 3 IndexError: list index out of range -

IF statement in MySQL trigger -