String y = "hello";
would work (note the double quotes).
char y = 'h'; this will work for chars (note the single quotes)
but the type is the key: '' (single quotes) for one char, "" (double quotes) for string.
Character only takes one value dude! like: char y = 'h'; and maybe you typed like char y = 'hello'; or smthg. good luck. for the question asked above the answer is pretty simple u have to use DOUBLE QUOTES to give a string value. easy enough;)
Java uses double quotes for "String"
and single quotes for 'C'
haracters.
I'd like to give a small addition to the existing answers. You get the same "Unclosed Character Literal error", if you give value to a char with incorrect unicode form. Like when you write:
char HI = '\3072';
You have to use the correct form which is:
char HI = '\u3072';
'' encloses single char
, while "" encloses a String
.
Change
y = 'hello';
-->
y = "hello";
Source: Stackoverflow.com