If this input has come from the user, how about trimming leading/trailing space using String.trim() )?