The Artima Developer Community
Sponsored Link

Java Buzz Forum
How to replace String in Java - character substring replaceAll example

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Javin Paul

Posts: 412
Nickname: javinpaul
Registered: Jan, 2012

Javin Paul is Java Programmer working on Finance domain.
How to replace String in Java - character substring replaceAll example Posted: Mar 23, 2013 9:53 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Javin Paul.
Original Post: How to replace String in Java - character substring replaceAll example
Feed Title: Java67
Feed URL: http://java67.blogspot.com/feeds/posts/default?alt=rss
Feed Description: Java and technology tutorials, tips, questions for all programmers.
Latest Java Buzz Posts
Latest Java Buzz Posts by Javin Paul
Latest Posts From Java67

Advertisement
String class in Java provides several methods to replace characters, CharSequence and substring from String in Java. Since String is immutable in Java, every time you performance an operation on String either replacement or removing white space from String, it generates a new String object. There are four overloaded method to replace String in Java :

replace(char oldChar, char newChar)
replace(CharSequence target, CharSequence replacement)
replaceAll(String regex, String replacement)
replaceFirst(String regex, String replacement)

Out of these, 2nd one which takes a CharSequence is added on Java 1.5. CharSequence is actually a super interface for String, StringBuffer and StringBuilder in Java, which means you can pass any of String, StringBuffer or StringBuilder Object as argument to this replace method. replaceFirst() and replaceAll() are very powerful and accepts regular expression. replaceFirst() only replace first match, while replaceAll replaces all matches with replacement String provided.
Read more ยป

Read: How to replace String in Java - character substring replaceAll example

Topic: Indexing data in Solr from disparate sources using Camel Previous Topic   Next Topic Topic: Introduction to Default Methods (Defender Methods) in Java 8


Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us