How to remove a particular character from a String.

Java 8Object Oriented ProgrammingProgramming

Following example shows how to remove a character from a particular position from a string with the help of removeCharAt(string, position) method.

Example

Live Demo

public class Sample {
   public static void main(String args[]) {
      String str = "this is Java";
      System.out.println(removeCharAt(str, 3));
   }
   public static String removeCharAt(String s, int pos) {
      return s.substring(0, pos) + s.substring(pos + 1);
   }
}

Output

this is Java
raja
Published on 12-Feb-2018 11:05:56
Advertisements