Java Program To Replace With New String

01. Example:

class StringMethods {
    public static void main(String args[]) {

        int N;
        String string01 = "Learn Java", newString = "", stringContact = "";
        System.out.println(string01);

        // Find length of string
        N = string01.length();
        System.out.println("Number Of Characters: " + N);

        // Replace Characters In String
        newString = string01.replace("Java", "Java And Python");
        System.out.println("nOld String: "+string01);
        System.out.println("After Replace New String: "+newString);

        // Concatenating string with another string
        stringContact = string01.concat(" With Zeroones.");
        System.out.println("nOld String: "+string01);
        System.out.println("After Concatenating Some String: "+stringContact);
    }
}

Output:

Learn Java
Number Of Characters: 10

Old String: Learn Java
After Replace New String: Learn Java And Python

Old String: Learn Java
After Concatenating Some String: Learn Java With Zeroones.

 

Leave a comment