- 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
Java Program to create Character Array from String Objects
Use the toCharArray() method in Java to create character arrays from string objects. The following is our string.
String str = "This is it!";
Now, let us create character array from the above string.
char[] strArr = str.toCharArray();
Example
public class Demo { public static void main(String[] args) { String str = "This is it!"; char[] strArr = str.toCharArray(); for(char res: strArr) { System.out.println(res); } } }
Output
T h i s i s i t !
Let us see another example in which we are creating string using new operator.
Example
public class Demo { public static void main(String[] args) { String str = new String("This is another string!"); char[] strArr = str.toCharArray(); for(char res: strArr) { System.out.println(res); } } }
Output
T h i s i s a n o t h e r s t r i n g !
- Related Articles
- Java Program to create Stream from a String/Byte Array
- Java program to convert a character array to string
- Creating String Object from Character Array in Java
- Java Program to Get a Character From the Given String
- How to create a string from a Java Array?
- Java Program to Convert Character to String
- Java Program to create a boolean variable from string
- Java Program to create DefaultTableModel from two dimensional array
- Java program for removing n-th character from a string
- Java Program to Create String from Contents of a File
- Java Program to access character of a string
- Creating String Object from certain part of a character Array in Java
- Search from an array of objects via array of string to get array of objects in JavaScript
- Java Program to create a BigDecimal from a string type value
- Golang Program to create a string array that takes inputs from users.

Advertisements