Search algorithms in Java