java.lang.StringIndexOutOfBoundsException: begin 0, end 10, length 5
substring()/charAt() used an index outside the string.
Seen on:
Java
Meaning
substring(begin, end) requires 0 ≤ begin ≤ end ≤ length. Short or empty input strings break fixed-length substrings.
Common causes
- Fixed substring lengths on shorter input
- Empty strings
- indexOf returning -1 used as an index
⚡ Quick fix
- Check length first: s.substring(0, Math.min(10, s.length()))
- Handle indexOf == -1
- Validate input
Detailed fix by platform
Java
String head = s.length() > 10 ? s.substring(0, 10) : s;
How to diagnose
- Indexes — begin/end/length in the message
- Input — Actual string value
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026