'char' data type array -
char defied arrays can store more than one character as shown in the below example -
Example -
char a[] = new char[4];
a[0] = 'a';
a[1] = 'r';
a[2] = 'u';
a[3] = 'n';
The above example represents a single dimensional char type array. We can also implement 2 dimensional, 3 dimensional arrays using the char data type. But in this post, I will only implement single dimensional char data type array.
Lets implement this on Eclipse IDE -
1. Launch Eclipse IDE, open Java Project 'Project Arrays' and create a new Java Class 'CharTypeArray' with main( ) method as shown below -
2. Write the below code to print the values stored in array elements as shown below -
3. Run the Java Class and observe that the 4 characters got printed in the output as shown below -
This is how we implement the char type arrays.
Lets implement the string type arrays in the next post.
Please comment below to feedback or ask questions.
'String' data type arrays will be explained in the next post.
No comments:
Post a Comment