---
title: "Write a method which will remove any given character from a String?"  
description: "Write a method which will remove any given character from a String?"  
author: "Ronan Jone"  
published: 2018-02-27  
canonical: https://answers.mindstick.com/qa/35070/write-a-method-which-will-remove-any-given-character-from-a-string  
category: "programming"  
reading_time: 2 minutes  

---

# Write a method which will remove any given character from a String?

## Answers

### Answer by Arti Mishra

We are using [java](https://www.mindstick.com/articles/1702/introduction-to-java) [language](https://www.mindstick.com/startup/28/preply-the-fast-growing-platform-transforming-language-learning) to solve your [queries](https://www.mindstick.com/blog/11168/introduction-to-sql)-

```
import java.util.*;
public class RemoveCharFromString
 {
    public static void main (String [] args)
        {
       Scanner sc=new Scanner(System.in);
             System.out.println("Enter Any String  : ");          String str=sc.nextLine();
             System.out.println("Enter Any Character Which You Want to remove  : ");
        char ch = sc.next().charAt(0);
          System.out.println (removeCharInString (str,  ch));
       }
/* Here is a method which will remove any given character from a String   */  public static String removeCharInString (String string, char charToBeRemoved) {
        if (string == null)
             return "";
         StringBuilder strBuild = new StringBuilder ();
        for (int i = 0; i < string.length (); i++) {
            char chr = string.charAt (i);
            if (chr == charToBeRemoved)
                continue;
            strBuild.append (chr);
        }
        return strBuild.toString ();
    }
}
```


---

Original Source: https://answers.mindstick.com/qa/35070/write-a-method-which-will-remove-any-given-character-from-a-string

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
