Two Pointer Technique Java