

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Copy characters from string into char Array in Java
Let’s say we have the following string.
String str = "Demo Text!";
To copy some part of the above string, use the getChars() method.
// copy characters from string into chArray =str.getChars( 0, 5, chArray, 0 );
The following is an example to copy characters from string into char Array in Java.
Example
public class Demo { public static void main(String[] args) { String str = "Demo Text!"; char chArray[] = new char[ 5 ]; System.out.println("String: "+str); // copy characters from string into chArray str.getChars( 0, 5, chArray, 0 ); System.out.print("Resultant character array...\n"); for (char ch : chArray) System.out.print( ch ); } }
Output
String: Demo Text! Resultant character array... Demo
- Related Questions & Answers
- Copy char array to string in Java
- Convert string to char array in Java
- Convert Char array to String in Java
- Java Program to convert Char array to String
- Constructing array from string unique characters in JavaScript
- Convert string to char array in C++
- Array Copy in Java
- How to copy a String into another String in C#
- How to convert an array of characters into a string in C#?
- Append a single character to a string or char array in java?
- Java Program to copy an array from the specified source array
- How can we copy one array from another in Java
- How to convert string to char array in C++?
- Java program to convert a list of characters into a string
- Why Char[] array is more secure (store sensitive data) than String in Java?
Advertisements