0
0

Javaにおけるシングルクォートとダブルクォートの違い

Last updated at Posted at 2024-02-24

シングルクォートで囲まれた文字は1文字のみを表し
ダブルクォートで囲まれた文字は複数の文字であることを示す。
1文字だけ変数に代入したい場合は

char a = 'a';

これでOK。

しかし、以下の場合は1文字限定のシングルクォートに対して複数の文字を代入しようとしているため
コンパイルエラーが発動される。

char a = 'aaa'

上記のように複数の文字を変数に代入したい場合は

String a = "aaa"

とすればOK。

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0