- 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 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...
"); for (char ch : chArray) System.out.print( ch ); } }
Output
String: Demo Text! Resultant character array... Demo
- Related Articles
- Copy char array to string in Java
- Convert Char array to String in Java
- Convert string to char array 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++
- 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?
- How to convert an array of characters into a string in C#?
- How can we copy one array from another in Java
- How to copy a String into another String in C#
- How to convert string to char array in C++?
- Java Program to copy an array from the specified source array
- Java program to convert a list of characters into a string

Advertisements