STRINGS

2. Program to perform Deep Copy for String?

            class Main{
                static String strDeepCopy(String str){
                    String newstr = "";
                    for(int i = 0; i < str.length(); i++){
                        newstr += str.charAt(i);
                    }
                    return newstr;
                }
                public static void main(String[] args){
                    String str = "Hello Everyone";
                    String cpystr = strDeepCopy(str);
                    System.out.println("Orignal String : " + str);
                    System.out.println("Copied String : " + cpystr);
                }
            }
        

OUTPUT

            Orignal String : Hello Everyone
            Copied String : Hello Everyone