move charAt to StringUtil and add boundary check