- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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
- Related Articles
- Java Program to Call One Constructor from another
- Java Program to divide one BigDecimal from another BigDecimal
- Java Program to copy value from one list to another list
- Java Program to check whether one String is a rotation of another.
- Java Program to Insert a string into another string
- Haskell Program to Call One Constructor from Another
- Golang program to call one constructor from another
- Replace one string with another string with Java Regular Expressions
- How to write a program to copy characters from one file to another in Java?
- How to call one constructor from another in Java?
- Java Program to copy all the key-value pairs from one Map into another
- Java Program to replace one specific character with another
- Program to get operations to convert one string to another in C++
- Add one Python string to another
- How to pass a String from one Activity to another in Android?

Advertisements