6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

文字列の比較

Last updated at Posted at 2015-07-16

文字列が等しいか調べるときは"=="ではなく"equals"

× if(a == "日の出") {
○ if(a.equals("日の出")) {

javaでは、条件式の中でString型の変数や文字列を比較するには、特別な書き方をする。

javaのルールでは文字列の比較は「==」ではできない。
文字列の比較を行う差にはa.equals()を使う。

文字列型の変数 .equals(比較相手の文字列)

※==を使ってもコンパイルエラーにはならず。
実行した際にたまに変な動きをする厄介な不具合になる。

6
7
2

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
6
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?