LoginSignup
0

More than 5 years have passed since last update.

javaで文字列の比較

Last updated at Posted at 2016-08-24
String str1;
String str2;

if(str1.equals(str2)) //str1とstr2を比較
    System.out.println("一致");

なぜstr1==str2ではダメなのか

"=="は、オブジェクト同士を比較する。
String型は、文字列が保存されているポインタを格納しているため、str1==str2だとうまくいかないのである。

だから当然int1==int2とかなら大丈夫

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