Remove first and last character of a string in Java

Remove first and last character of a string in Java

In this post we will give you information about Remove first and last character of a string in Java. Hear we will give you detail about Remove first and last character of a string in JavaAnd how to use it also give you demo for it if it is necessary.

we are going to learn how to remove the first and last character of a string in Java.

Using the substring() method

To remove the first and last character of a string, we can use the substring() method by passing 1 as a first argument and string.length()-1 as the second argument in Java.

Here is an example, which removes the first character h and last character o from the following string:

String str = "hello";System.out.println(str.substring(1,str.length() - 1));

Output:

ell

In the example above, the extraction starts from index 1 and ends before the last index (that is string.length()-1).

Hope this code and post will helped you for implement Remove first and last character of a string in Java. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US