public class BoyerMoore { private static int search(String txt,String pat){ int[] right=new int[256]; final int N=txt.length(); final int M=pat.length(); for(int i=0;i<right.length;i++){ right[i]=-1; } for(int i=0;i<M;i++){ right[pat.charAt(i)]=i; } for(int i=0,skip=0;i<=N-M;i+=skip){ skip=0; for(int j=M-1;j>=0;j--){ if(txt.charAt(i+j)!=pat.charAt(j)){ skip=j-right[txt.charAt(i+j)]; if(skip<1) skip=1; break; } } if(skip==0) return i; } return -1; } public static void main(String[] args){ String txt="aaawe24reterg"; String pat="awe"; System.out.println(search(txt, pat)); } }