Java – String replaceFirst() Example, Strings replaceFirst() program

First String sequence can be replaced with other string literal the help of replaceFirst() method in java. replaceFirst() method returns a value in String. replaceFirst method replace string character with first occurrences in string sequence. Use of String replaceFirst() in java is shown below.

Example of String replaceFirst() in java, JSP

public class StringReplaceAllExample {

    public static void main(String[] args) {

        String string = "Find String and replace All String";

        String newString = string.replaceAll("String", "New");

        System.out.println("Output :"+newString);
    }
}

Output

Output :Find First and replace First word String

Tags:

Bookmark  

 

Leave a Reply

Security Code:

 

  Random Post