Friday 11 March 2016

How to Remove First and Last Character of String in Java - Example Tutorial

You can use the substring() method of java.lang.String class to remove the first or last character of String in Java. The substring() method is overloaded and provides a couple of versions which allows you to remove a character from any position in Java. Alternatively, you can convert String to StringBuffer or StringBuilder and then use its remove() method to remove the first or last character. Both StringBuffer and StringBuilder provides a convenient deleteCharAt(int index) method which removes a character from the corresponding index. You can use this method to remove both first and last character from String in Java. In the last article, I have showed you how to get the first and last character from String and today I will teach you how to remove the first and last character of String in Java. Let's see a couple of examples and how you can use these two techniques to solve this problem.
Read more »

No comments:

Post a Comment