Java: remove the first character of a string
Codemia Knowledge Hub ·
Use value.substring(1). It returns everything from index 1 onward, which drops the first UTF-16 char. If the string can be empty or null, check first, and if it can start with an emoji or another supplementary character, skip one code point with offsetByCodePoints instead.
substring(1) for ordinary text
Java strings are zero-indexed, so index 1 means "start from the second position and keep the rest". For most business code this is all you need: short, readable and fast enough.
Handling null and empty strings
substring(1) throws StringIndexOutOfBoundsException on an empty string, and calling it on null throws NullPointerException. Decide what the method should return in those cases and code it explicitly:
That check makes the method safe for external input, CSV data, request parameters and other unreliable sources.
Removing the first code point for emoji and Unicode
Java strings are stored as UTF-16, and some user-visible characters, including many emoji, take two char values. substring(1) then removes only half of the pair and leaves invalid text:
If your input can contain supplementary characters (names, chat text, emoji), remove the first code point instead:
This advances by one code point rather than one UTF-16 unit.
StringBuilder.deleteCharAt(0) for repeated edits
When you are making several edits as part of a larger transformation, a mutable builder can be easier:
For a single removal, substring() is simpler. Strings are immutable, so you get a new string either way, and a builder only pays off for multiple mutations. deleteCharAt(0) has the same Unicode limitation as substring(1), because it removes one char, not one code point.
Which "first character" you mean
There are three common interpretations:
- first
char - first Unicode code point
- first grapheme cluster as seen by the user
For most Java code, choosing between char and code point is enough. Full grapheme-cluster handling is a more advanced problem that usually needs specialized libraries. In practice:
- use
substring(1)for simple text - use
offsetByCodePointswhen Unicode correctness matters
In validation code, such as stripping a leading sign from numeric text or a prefix from IDs, check that the first character is what you expect before dropping it.
Related reading
- Java - sending HTTP parameters via POST method easily
- Java - Sort one array based on values of another array?
- Java 11 on AWS beanstalk for Spring boot project
- Java 11 package javax.xml.bind does not exist
- Java 256-bit AES Password-Based Encryption
- Java 7 language features with Android
- Java 8 Class JavaLaunchHelper is implemented in both
- Java 8 date/time type java.time.Instant not supported by default Issue
System design interview problems on this topic
- Design an API Rate Limiter: solution and walkthrough
- Design a Distributed Messaging System: solution and walkthrough
- Design an Online Payment Service: solution and walkthrough
- Design a Key Value Store: solution and walkthrough

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.