java find the occurrences of substring in a string

java find the occurrences of substring in a string
/**
 * @author lautturi.com
 * Java example: count the substring in java string
 */

import java.util.*;

public class Lautturi {

	public static void main(String[] args) {

		String str = "java python hellojavaworld perllautturi Java";
		String findStr = "java";
		int lastIndex = 0;
		int count = 0;
		while(lastIndex != -1){
		    lastIndex = str.indexOf(findStr,lastIndex);
		    if(lastIndex != -1){
		        count ++;
		        lastIndex += findStr.length();
		    }
		}
		System.out.println(count);
	}
}
Source‮www:‬.lautturi.com

output:

2
Created Time:2017-09-11 11:05:55  Author:lautturi