-
/*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
-
What you'll learn Understand why version control is a fundamental tool for coding and collaboration Install and run Git on your local ...
-
Explanation of the Code s = 'robot' # Assign the string 'robot' to variable s a, b, c, d, e = s # Unpacking the string ...
-
Python has one of the richest ecosystems of libraries and tools, making it a favorite for developers worldwide. GitHub is the ultimate tre...
-
Step-by-Step Execution: First Iteration (a = 0) b = 0 → d[0] = 0 b = 1 → d[0] = 1 (overwrites previous value) b = 2 → d[0] = 2 (overwrites...
-
Step-by-step Execution: Define a Set: set1 = { 10 , 20 , 30 } set1 is a set containing {10, 20, 30}. Remove an Element: set2 = set1.remove...
-
What you'll learn Develop data engineering solutions with a minimal and essential subset of the Python language and the Linux environm...
-
📝 1. Swap Two Variables Without a Temp Variable a, b = 5 , 10 a, b = b, a print(a, b) Output: 10 5 📏 2. Check if a String is a Palindrom...
-
Step-by-Step Execution: Function Definition: python def extend_list ( lst ): lst.extend([10]) The function extend_list(lst) takes a l...
-
Explanation: String Indexing The string "Python" consists of characters indexed as follows: P y t h o n 0 1 2 3 4 5 Each charact...
-
Master data visualization with Matplotlib using this ultimate cheat sheet ! This PDF book provides 50 different plot types , covering ev...
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
(188)
C
(77)
C#
(12)
C++
(83)
Course
(67)
Coursera
(247)
Cybersecurity
(25)
Data Analysis
(1)
Data Analytics
(2)
data management
(11)
Data Science
(142)
Data Strucures
(8)
Deep Learning
(21)
Django
(16)
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)
pyth
(1)
Python
(1004)
Python Coding Challenge
(449)
Python Quiz
(86)
Python Tips
(4)
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