-
/*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
-
Activity_main.xml File <? xml version= "1.0" encoding= "utf-8" ?> < LinearLayout xmlns: android = &qu...
-
Procedure Oriented Programming Language:- High level language such as COBOL , FORTRAN AND C is commonly known as procedure oriented progr...
-
Activity Main : <? xml version ="1.0" encoding ="utf-8" ?> < androidx.constraintlayout.widget.ConstraintLayout...
-
Build.gradle File:- implementation 'com.google.android.material:material:1.3.0' implementation 'com.squareup.retrofit2:retr...
-
Advantages of Object Oriented Programming Object oriented programming has several advantage to the programmer and user. Through inheri...
-
There are many programming languages, each corresponding to specific needs (formula calculus, character string processing, real-time, etc.)...
-
Build interactive, data-driven websites with the potent combination of open-source technologies and web standards, even if you have only ...
-
Pseudocode is a compact and informal high-level description of a computer programming algorithm. Pseudo-code typically omits details tha...
-
What is Python? → Python is an interpreted High level programming Language for General purpose programming. Python is created by Gui...
-
Introduction: In today's digital age, where typing on keyboards and tapping on screens has become the norm, there is something truly mag...
Categories
Android
(23)
AngularJS
(1)
Assembly Language
(2)
Books
(10)
C
(75)
C#
(12)
C++
(81)
Course
(1)
Data Strucures
(4)
Downloads
(1)
Engineering
(13)
flutter
(1)
FPL
(17)
Hadoop
(1)
HTML&CSS
(40)
IS
(25)
Java
(89)
Leet Code
(4)
Pandas
(2)
PHP
(20)
Projects
(19)
Python
(434)
R
(69)
Selenium Webdriver
(2)
Software
(14)
SQL
(27)
0 Comments:
Post a Comment