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
Category: Java Programming String Programs Tags:

About Tunde A

My name is Tunde Ajetomobi, a Tech Enthusiast and Growth Hacker. I enjoy creating helpful content that solves problem across different topics. Codezclub is my way of helping young aspiring programmers and students to hone their skills and find solutions on fundamental programming languages.

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments