Write a Java Program to Copy String into Another String

By | 09.02.2017

Java Program to Copy String into Another String


Java Program to copy string in Java Programming, you have to ask to the user to enter the string to make copy to another variable say strCopy and display this variable which is the copied value of the given string as shown in the following program.

 

SOURCE CODE ::

 

import java.util.Scanner;

public class Copy_String
{
   public static void main(String args[])
   {
      String strOrig;
      Scanner scan = new Scanner(System.in);
 
      System.out.print("Enter a String : ");
      strOrig = scan.nextLine();
      
      System.out.print("Copying String...\n");
      
      StringBuffer strCopy = new StringBuffer(strOrig);
      
      System.out.print("String Copied Successfully..!!\n");      
      System.out.print("The Copied String is " + strCopy);
   }
}

 

OUTPUT ::

 

Enter a String : Codezclub
Copying String...
String Copied Successfully..!!
The Copied String is Codezclub

 

4 1 vote
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments