-
/*Java String replace example.This Java String Replace example describes how replace method of java String classcan be used to replace character or substring can be replaced by new one.*/public class JavaStringReplaceExample{
public static void main(String args[]){
/*Java String class defines three methods to replace character or substring fromthe given Java String object.1) String replace(int oldChar, int newChar)This method replaces a specified character with new character and returns anew string object.2) String replaceFirst(String regularExpression, String newString)Replaces the first substring of this string that matches the given regularexpression with the given new string.3) String replaceAll(String regex, String replacement)Replaces the each substring of this string that matches thegiven regular expression with the given new string.*/
String str=“Replace Region”;
/*Replaces all occourances of given character with new one and returns newString object.*/System.out.println( str.replace( ‘R’,‘A’ ) );
/*Replaces only first occourances of given String with new one andreturns new String object.*/System.out.println( str.replaceFirst(“Re”, “Ra”) );
/*Replaces all occourances of given String with new one and returnsnew String object.*/System.out.println( str.replaceAll(“Re”, “Ra”) );
}
}
/*OUTPUT of the above given Java String Replace Example would be :Aeplace AegionRaplace RegionRaplace Ragion*/
Friday, 13 April 2018
Popular Posts
-
Build interactive, data-driven websites with the potent combination of open-source technologies and web standards, even if you have only ...
-
Java :- It is a fast, secure and reliable general purpose computer programming language. Python :- A Readable, efficient and powerfu...
-
Business Analytics Definition "Study of business data using statistical technique and programming for creating decision suppo...
-
Variables in R A variables are nothing but reserved memory locations to store values. This means that when you create a variab...
-
What is Python? → Python is an interpreted High level programming Language for General purpose programming. Python is created by Gui...
-
Why do we need Analytics ? → Data analytics helps organizations harness their data and use it to identify few opportunities. - Cost re...
-
- > is the prompt sign in R - The assignment operators are the left arrow with dash <- and equal sign =. > x <- 20 ...
-
Java is develop by James Gosling in 1991 Java is a developed in the early 90s in Sun Microsystems company. Java first version release in ...
-
Importing Data Files Spreadsheet (Excel) file data The xlsx package has the function read.xlsx ( ) for reading Excel files. This ...
-
1. Simple & Easy To Learn Open Source High-level Interpreted Large community 2. Portable & Extensible 3. Web ...

0 Comments:
Post a Comment