Knuth Morris Pratt Algorithm in Java