シングルクォートで囲まれた文字は1文字のみを表し
ダブルクォートで囲まれた文字は複数の文字であることを示す。
1文字だけ変数に代入したい場合は
char a = 'a';
これでOK。
しかし、以下の場合は1文字限定のシングルクォートに対して複数の文字を代入しようとしているため
コンパイルエラーが発動される。
char a = 'aaa'
上記のように複数の文字を変数に代入したい場合は
String a = "aaa"
とすればOK。
Go to list of users who liked
シングルクォートで囲まれた文字は1文字のみを表し
ダブルクォートで囲まれた文字は複数の文字であることを示す。
1文字だけ変数に代入したい場合は
char a = 'a';
これでOK。
しかし、以下の場合は1文字限定のシングルクォートに対して複数の文字を代入しようとしているため
コンパイルエラーが発動される。
char a = 'aaa'
上記のように複数の文字を変数に代入したい場合は
String a = "aaa"
とすればOK。
Register as a new user and use Qiita more conveniently
Go to list of users who liked