java get first n characters of string code example Example: get first 5 characters of string java firstFourChars = input.substring(0, 4);