How to remove char from a String

0 votes

Can someone guide me, how can I remove all the occurrences of a specific char from a given String?

Suppose, I want to remove ‘X’ from the below String:

String str = "CharacterX XtoX ReplaceX"; 
May 21, 2018 in Java by v.liyyah
• 1,300 points
185 views

1 answer to this question.

0 votes

Hi...here you can try using the overloaded method of replace() which takes “String” as input, and write the code as below:

str = str.replace("X", "");

Hope this helps.

answered May 21, 2018 by code.reaper12
• 3,500 points

Related Questions In Java

0 votes
1 answer

How to remove the last character from a string?

Hi@akhtar, You can use the StringBuffer class. It provides ...READ MORE

answered Dec 30, 2020 in Java by MD
• 95,200 points
114 views
0 votes
1 answer

How can we remove html tags from a string?

You can use HTML parser. This is ...READ MORE

answered Jun 4, 2018 in Java by sophia
• 1,400 points
945 views
0 votes
1 answer

How to Read/Write String from a File in Android

Writing a File in android: private void writeToFile(String ...READ MORE

answered Oct 3, 2018 in Java by sharth
• 3,350 points
4,318 views
0 votes
1 answer

How to get an enum value from a string value in Java?

Hello @kartik, Yes, Blah.valueOf("A") will give you Blah.A. Note that the name ...READ MORE

answered Jul 28, 2020 in Java by Niroj
• 82,760 points
563 views
+5 votes
4 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,450 points

edited Nov 6, 2018 by Omkar 43,874 views
+1 vote
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,520 points
5,581 views
0 votes
1 answer

What are the differences between getText() and getAttribute() functions in Selenium WebDriver?

See, both are used to retrieve something ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,520 points
12,191 views
0 votes
1 answer

Selenium JARS(Java) missing from downloadable link

Nothing to worry about here. In the ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,520 points
2,340 views
0 votes
1 answer

How to download a file from spring controllers?

@RequestMapping(value = "/files/{file_name}", method = RequestMethod.GET) public void ...READ MORE

answered Sep 4, 2018 in Java by code.reaper12
• 3,500 points
1,088 views
0 votes
1 answer

How to refresh a JTable model after insert delete or update the data

In my opinion, you can notify your ...READ MORE

answered Oct 10, 2018 in Java by code.reaper12
• 3,500 points
13,191 views