- 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
Copy char array to string in Java
Use the valueOf() method in Java to copy char array to string. You can also use the copyValueOf() method, which represents the character sequence in the array specified. Here, you can specify the part of array to be copied.
Let us first create a character array.
char[] arr = { 'p', 'q', 'r', 's' };
The method valueOf() will convert the entire array into a string.
String str = String.valueOf(arr);
The following is an example.
Example
public class Demo { public static void main(String []args) { char[] arr = { 'p', 'q', 'r', 's' }; String str = String.valueOf(arr); System.out.println(str); } }
Output
Pqrs
Let us see another example that use copyValueOf() method that convert char array to string.
Example
public class Demo { public static void main(String []args) { char[] arr = { 'p', 'q', 'r', 's' }; String str = String.copyValueOf(arr, 1, 2); System.out.println(str); } }
Output
Qr
- Related Articles
- Copy characters from string into char Array in Java
- Convert string to char array in Java
- Convert Char array to String in Java
- Java Program to convert Char array to String
- Convert string to char array in C++
- Append a single character to a string or char array in java?
- How to convert string to char array in C++?
- Different methods to append a single character to a string or char array in Java
- Array Copy in Java
- Why Char[] array is more secure (store sensitive data) than String in Java?
- Java Program to fill elements in a char array
- Java Program to implement Binary Search on char array
- How to convert an std::string to const char* or char* in C++?
- How to convert a std::string to const char* or char* in C++?
- Copy all elements in Java TreeSet to an Object Array

Advertisements