<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[All about .replaceAll() in Java]]></title><description><![CDATA[<p dir="auto"><img src="https://miro.medium.com/max/1200/1*xAF5CV-eSKvtvN8tLLbOQA.jpeg" alt="alt text" class=" img-responsive img-markdown" /><br />
java.lang.String class brings you a very powerful method to do replacements within a string.</p>
<p dir="auto">This method allows you to target specific substrings using regular expression ,so that you can even remove and replace any pattern within a string.</p>
<p dir="auto">Mainly, this method can</p>
<pre><code>     * replace a given substring found any where in the string
     * replace a given character found any where in the string
     * replace a given reg expression found any where in the string
</code></pre>
<p dir="auto">Even though there are separate methods like replace(char old, char new), replace(charSequence old, charSequence new) to do above functions, this replaceAll() method acts as a versatile method for all those functions.</p>
<p dir="auto">This is how this method is defined in String class,</p>
<p dir="auto"><strong>String</strong> replaceAll(<strong>String</strong> regex , <strong>String</strong> new)</p>
<p dir="auto">As you can see , this method returns a new string. Actually, a string is <strong>immutable</strong> in JAVA , so it is not possible to alter a string. This method returns a new string instead.You need to catch it with a string variable.</p>
<p dir="auto">**This method accepts to two parameters which must be in type String. So , when you need to replace a character, you have to use a <strong>double quotation</strong> for the characters (instead of single quotations which are used for representing char).</p>
<p dir="auto"><strong>Examples:</strong></p>
<p dir="auto"><img src="https://miro.medium.com/max/800/0*2jW-NO0ftBjJ3NCT.png" alt="alt text" class=" img-responsive img-markdown" /><br />
Character replacement</p>
<p dir="auto"><img src="https://miro.medium.com/max/800/0*3xQEmOafsZuusK24.png" alt="alt text" class=" img-responsive img-markdown" /><br />
String replacement</p>
<p dir="auto"><img src="https://miro.medium.com/max/800/0*YfCdS722xvMw_YaA.png" alt="alt text" class=" img-responsive img-markdown" /><br />
Regex replacement</p>
<p dir="auto">Keep in Touch!!!</p>
]]></description><link>https://lankadevelopers.lk/topic/419/all-about-replaceall-in-java</link><generator>RSS for Node</generator><lastBuildDate>Tue, 14 Apr 2026 12:10:48 GMT</lastBuildDate><atom:link href="https://lankadevelopers.lk/topic/419.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 23 Oct 2019 18:13:19 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to All about .replaceAll() in Java on Thu, 24 Oct 2019 08:36:35 GMT]]></title><description><![CDATA[<p dir="auto">good work bro</p>
]]></description><link>https://lankadevelopers.lk/post/2421</link><guid isPermaLink="true">https://lankadevelopers.lk/post/2421</guid><dc:creator><![CDATA[Nubelle]]></dc:creator><pubDate>Thu, 24 Oct 2019 08:36:35 GMT</pubDate></item><item><title><![CDATA[Reply to All about .replaceAll() in Java on Thu, 24 Oct 2019 04:56:27 GMT]]></title><description><![CDATA[<p dir="auto">awesome bro</p>
]]></description><link>https://lankadevelopers.lk/post/2418</link><guid isPermaLink="true">https://lankadevelopers.lk/post/2418</guid><dc:creator><![CDATA[dev_lak]]></dc:creator><pubDate>Thu, 24 Oct 2019 04:56:27 GMT</pubDate></item><item><title><![CDATA[Reply to All about .replaceAll() in Java on Wed, 23 Oct 2019 19:35:45 GMT]]></title><description><![CDATA[<p dir="auto">keep it up. awesome</p>
]]></description><link>https://lankadevelopers.lk/post/2417</link><guid isPermaLink="true">https://lankadevelopers.lk/post/2417</guid><dc:creator><![CDATA[root]]></dc:creator><pubDate>Wed, 23 Oct 2019 19:35:45 GMT</pubDate></item></channel></rss>