
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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
Construct One String from Another in Java
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