-
/*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
-
The error is happening because Python does not support the ++ operator for incrementing a variable Explanation of the code: i = 0 while i ...
-
Prepare for a career as a full stack developer. Gain the in-demand skills and hands-on experience to get job-ready in less than 4 months. ...
-
What you'll learn Automate tasks by writing Python scripts Use Git and GitHub for version control Manage IT resources at scale, both for...
-
Explanation: Step 1: a = [1, 2, 3, 4, 5] A list a is created with the values [1, 2, 3, 4, 5]. Step 2: b = a The variable b is assigned t...
-
Code Explanation: i = 0 The variable i is initialized to 0. while i < 5 : A while loop is started, which will run as long as the condi...
-
The given code defines a function gfg that takes two arguments: x: An integer that specifies how many iterations the loop will run. li: A ...
-
Python is beloved for its rich ecosystem of libraries that simplify programming tasks. But did you know that for many popular libraries, t...
-
Code: my_list = [ 3 , 1 , 10 , 5 ] my_list = my_list.sort() print(my_list) Step 1: Creating the list my_list = [ 3 , 1 , 10 , 5 ] A list n...
-
Python has quickly become one of the most popular programming languages worldwide, and for good reason. It's versatile, easy to learn, a...
-
Explanation: Assignment ( x = 7, 8, 9 ): Here, x is assigned a tuple (7, 8, 9) because multiple values separated by commas are automatical...
Categories
100 Python Programs for Beginner
(96)
AI
(38)
Android
(24)
AngularJS
(1)
Assembly Language
(2)
aws
(17)
Azure
(7)
BI
(10)
book
(4)
Books
(186)
C
(77)
C#
(12)
C++
(83)
Course
(67)
Coursera
(246)
Cybersecurity
(25)
Data Analysis
(1)
Data Analytics
(2)
data management
(11)
Data Science
(141)
Data Strucures
(8)
Deep Learning
(21)
Django
(14)
Downloads
(3)
edx
(2)
Engineering
(14)
Euron
(29)
Excel
(13)
Factorial
(1)
Finance
(6)
flask
(3)
flutter
(1)
FPL
(17)
Generative AI
(9)
Google
(34)
Hadoop
(3)
HTML Quiz
(1)
HTML&CSS
(47)
IBM
(30)
IoT
(1)
IS
(25)
Java
(93)
Java quiz
(1)
Leet Code
(4)
Machine Learning
(76)
Meta
(22)
MICHIGAN
(5)
microsoft
(4)
Nvidia
(4)
Pandas
(4)
PHP
(20)
Projects
(29)
Python
(994)
Python Coding Challenge
(444)
Python Quiz
(75)
Python Tips
(3)
Questions
(2)
R
(70)
React
(6)
Scripting
(1)
security
(3)
Selenium Webdriver
(4)
Software
(17)
SQL
(42)
UX Research
(1)
web application
(8)
Web development
(4)
web scraping
(2)
0 Comments:
Post a Comment