 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to construct one String from another
To construct on string from another, firstly take a charcter array for the first string.
char ch[] = { 'A', 'M', 'I', 'T' }; String str1 = new String(ch); The above forms first string. Now, let us created another string from the first string.
String str2 = new String(str1);
In this way, we can easily construct one string from another.
Example
public class Demo {    public static void main(String[] args) {       char ch[] = { 'A', 'M', 'I', 'T' };       String str1 = new String(ch);       String str2 = new String(str1);       String str3 = new String(str2);       System.out.println("String 1: "+str1);       System.out.println("String 2: "+str2);       System.out.println("String 3: "+str3);    } }  Output
String 1: AMIT String 2: AMIT String 3: AMIT
Advertisements
 