Languages
[Edit]
EN

Java - remove last character from string

14 points
Created by:
Root-ssh
177980

1. Overview

Edit

In this post we will see how to remove last character from String in java.

All below examples except StringUtils.chop can be used to remove any number of characters from the end of the string.

Example:

2. Remove last char with String.substring

Edit

Code example: 

Output:

3. Remove last char with StringBuilder.delete

Edit

Code example: 

Output:

4. Remove last char with Java 8 Optional

Edit

Code example: 

Output:

5. Remove last char with Apache Commons - StringUtils.chop

Edit

Code example:

Output:

6. Remove last char with Apache Commons - StringUtils.substring()

Edit

Code example: 

Output:

References

Edit
  1. String.substring - Java docs
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Cross technology - remove last character from string

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join