- 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
Convert string to char array in Java
The following is our string.
String str = "Tutorial";
Now, use the toCharArray() method to convert string to char array.
char[] ch = str.toCharArray();
Now let us see the complete example.
Example
public class Demo { public static void main(String []args) { String str = "Tutorial"; System.out.println("String: "+str); char[] ch = str.toCharArray(); System.out.println("Character Array..."); for (int i = 0; i < ch.length; i++) { System.out.print(ch[i]+" "); } } }
Output
String: Tutorial Character Array... T u t o r i a l
Advertisements