Java get indexes of all occurrences of character in a string

w‮al.ww‬utturi.com
Java get indexes of all occurrences of character in a string
/**
 * @author lautturi.com 
 * Java example: get indexes of finding character in string
 */

public class Lautturi {

	public static void main(String[] args) {
		String str = "hello Lautturi java";
		String letter = "a";

		int index = str.indexOf(letter);
		while (index >= 0) {
		    System.out.println(index);
		    index = str.indexOf(letter, index + 1);
		}

	}

}

output:

7
16
18
Created Time:2017-09-23 14:54:49  Author:lautturi