Character array basic query | Selenium Forum
M
Mohammed Sajjad Posted on 12/07/2020
Hi there,

Since the default value of char is \u000 which would be the unicode representation of a character with ASCII code 0.
So, I tried to insert an integer in the character array. See below:

class Example {
public static void main(String[] args) {
char[] arr = new char[2];
arr[0] = 2; // Is this allowed
arr[1] = 'a';
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
}
}
And I got this wierd output:
Output:

a

I was just trying to understand why the program didn't give me compilation error and if this is allowed?

M
Mohammed Sajjad Replied on 14/07/2020

Guys??? Can anyone please answer this?


A
Ashish Replied on 15/07/2020

A compilation error will not come here as it takes the Unicode equivalent

If you want to print 2 you can include in single quotes


Related Posts