string.replaceFirst()
String.replaceFirst() replace First occurrence of matching char or string .
Here are some examples with output.
Replacing char
String str = "Welcome to plus2net.com";
System.out.println(str.replaceFirst("o","*"));
Output is here
Welc*me to plus2net.com
Replacing string
String str = "Welcome to plus2net.com";
System.out.println(str.replaceFirst("com","net"));
Output is here
Welnete to plus2net.com
Note : In above code, there is one replacement.
« All String functions
« Java
This article is written by plus2net.com team.
plus2net.com