{"id":165,"date":"2023-12-10T17:19:10","date_gmt":"2023-12-10T08:19:10","guid":{"rendered":"https:\/\/se-pg-toolbox.com\/?p=165"},"modified":"2023-12-10T17:19:11","modified_gmt":"2023-12-10T08:19:11","slug":"java%e3%81%ae%ef%bc%9d%ef%bc%9d%e3%81%ab%e3%82%88%e3%82%8b%e6%96%87%e5%ad%97%e5%88%97%e5%90%8c%e5%a3%ab%e3%80%81%e6%95%b0%e5%80%a4%e5%90%8c%e5%a3%ab%e3%81%ae%e6%af%94%e8%bc%83%e3%81%ae%e8%80%83","status":"publish","type":"post","link":"https:\/\/se-pg-toolbox.com\/?p=165","title":{"rendered":"Java\u306e\uff1d\uff1d\u306b\u3088\u308b\u6587\u5b57\u5217\u540c\u58eb\u3001\u6570\u5024\u540c\u58eb\u306e\u6bd4\u8f03\u306e\u8003\u3048\u65b9"},"content":{"rendered":"\n<p>\u4eca\u56de\u306fJava\u3092\u4f7f\u3046\u6642\u306b\u3001\u521d\u5fc3\u8005\u304c\u30df\u30b9\u3092\u72af\u3057\u3084\u3059\u3044==\u306e\u7b49\u53f72\u3064\u306e\u6bd4\u8f03\u306b\u3064\u3044\u3066\u304a\u8a71\u3057\u3057\u307e\u3059\u3002<br><br>\u57fa\u672c\u7684\u306b\u6587\u5b57\u5217\u306e\u6bd4\u8f03\u3067==\u3092\u4f7f\u3063\u3066\u306f\u3044\u3051\u306a\u3044\u3053\u3068\u3092\u7406\u89e3\u3057\u3066\u304a\u3051\u3070\u5341\u5206\u3067\u3059\u304c\u3001\u9593\u9055\u3063\u3066\u4f7f\u3063\u3066\u3057\u307e\u3063\u305f\u5834\u5408\u3082\u666e\u901a\u306b\u6b63\u3057\u3044\u6bd4\u8f03\u304c\u51fa\u6765\u3066\u3057\u307e\u3046\u30b1\u30fc\u30b9\u3082\u3042\u308a\u307e\u3059\u3002<br><br>\u3053\u308c\u306f\u306a\u305c\u306a\u306e\u304b\u306b\u3064\u3044\u3066\u3082\u304a\u8a71\u3057\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Java\u306e=\uff1d\u306b\u3088\u308b\u6570\u5024\u6bd4\u8f03\u306e\u8003\u3048\u65b9<\/h2>\n\n\n\n<p>\u307e\u305a\u3001Java\u306b\u304a\u3044\u3066<span class=\"marker\">\u6570\u5024\u306e\u6bd4\u8f03\u306f\u666e\u901a\u306b==\u3092\u4f7f\u3063\u3066\u554f\u984c\u3042\u308a\u307e\u305b\u3093<\/span>\u3002<br><br>\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30e1\u30bd\u30c3\u30c9\u3092\u5b9a\u7fa9\u3057\u3066\u547c\u3073\u51fa\u3059\u3053\u3068\u3067\u3001\u5b9f\u884c\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>\t\/\/\u6570\u5024\u540c\u58eb\u3092\u6bd4\u8f03\u3057\u3066\u307f\u308b\n\tpublic void CompareInt2Int() {\n\t\tint int1 = 8;\n\t\tint int2 = 8;\n\t\t\/\/equals\u3067\u6bd4\u8f03\u3057\u3066\u307f\u308b\uff08\u7b49\u53f7\u306e\u52d5\u4f5c\u304c\u6b63\u3057\u3051\u308c\u3070\u300c\u7b49\u3057\u3044\u300d\u3068\u8868\u793a\u3055\u308c\u308b\uff09\n\t\tif(int1 == int2) {\n\t\t\tSystem.out.println(&quot;\u7b49\u3057\u3044&quot;);\n\t\t} else {\n\t\t\tSystem.out.println(&quot;\u7b49\u3057\u304f\u306a\u3044&quot;);\n\t\t}\n\t}<\/code><\/pre><\/div>\n\n\n\n<p>\u3053\u306e\u5224\u5b9a\u7d50\u679c\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"801\" height=\"261\" src=\"https:\/\/se-pg-toolbox.com\/wp-content\/uploads\/2023\/12\/article10-1.png\" alt=\"\u6570\u5024\u540c\u58eb\u306e==\u306b\u3088\u308b\u6bd4\u8f03\" class=\"wp-image-166\" \/><\/figure>\n\n\n\n<p>\u7121\u4e8b\u306b2\u3064\u306e\u5909\u6570\u306b\u5165\u308c\u305f\u6570\u5024\u304c\u7b49\u3057\u3044\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3057\u305f\u3002<br><br>int\u306a\u3069\u306e\u3088\u3046\u306b\u540c\u3058\u578b\u306e\u6570\u5024\u540c\u58eb\u306e\u6bd4\u8f03\u3067\u3042\u308c\u3070==\u3067\u6bd4\u8f03\u3057\u3066\u7279\u306b\u554f\u984c\u3042\u308a\u307e\u305b\u3093\u3002<br><br>C\u8a00\u8a9e\u3068\u540c\u3058\u611f\u899a\u3067==\u3092\u4f7f\u3063\u3066\u554f\u984c\u304c\u306a\u3044\u3067\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Java\u306e=\uff1d\u306b\u3088\u308b\u6587\u5b57\u5217\u6bd4\u8f03\u306e\u8003\u3048\u65b9<\/h2>\n\n\n\n<p>Java\u306e\u6587\u5b57\u5217\u540c\u58eb\u3067==\u3092\u4f7f\u3063\u3066\u6bd4\u8f03\u3059\u308b\u4f7f\u3044\u65b9\u3067\u3059\u304c\u3001<span class=\"marker\">\u540c\u3058\u30a2\u30c9\u30ec\u30b9\u3067\u540c\u3058\u5024\u306e\u5834\u5408\u306b\u7b49\u3057\u3044<\/span>\u3068\u5224\u5b9a\u3055\u308c\u307e\u3059\u3002<br><br>\u3044\u304f\u3064\u304b\u4f8b\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<br>\u307e\u305a\u306f\u3001\u7570\u306a\u308b\u5909\u6570\u306b\u540c\u3058\u6587\u5b57\u5217\u3092\u5b9a\u7fa9\u3057\u3066\u6bd4\u8f03\u3057\u305f\u5834\u5408\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>\t\/\/\u6587\u5b57\u5217\u540c\u58eb\u3092\u6bd4\u8f03\u3059\u308b\n\tpublic void CompareStr2Str1() {\n\t\tString str1 = &quot;apple&quot;;\n\t\tString str2 = &quot;apple&quot;;\n\t\t\/\/\u901a\u5e38\u306e\u7b49\u53f7\u3067\u6bd4\u8f03\u3057\u3066\u307f\u308b\uff08\u7b49\u53f7\u306e\u52d5\u4f5c\u304c\u6b63\u3057\u3051\u308c\u3070\u300c\u7b49\u3057\u3044\u300d\u3068\u8868\u793a\u3055\u308c\u308b\uff09\n\t\tif(str1 == str2) {\n\t\t\tSystem.out.println(&quot;\u7b49\u3057\u3044&quot;);\n\t\t} else {\n\t\t\tSystem.out.println(&quot;\u7b49\u3057\u304f\u306a\u3044&quot;);\n\t\t}\n\t}<\/code><\/pre><\/div>\n\n\n\n<p>\u3053\u306e\u5834\u5408\u306e\u5b9f\u884c\u7d50\u679c\u3092\u898b\u3066\u307f\u308b\u3068\u30fb\u30fb\u30fb<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"799\" height=\"262\" src=\"https:\/\/se-pg-toolbox.com\/wp-content\/uploads\/2023\/12\/article10-2.png\" alt=\"\u6587\u5b57\u5217\u540c\u58eb\u306e==\u306b\u3088\u308b\u6bd4\u8f03\" class=\"wp-image-167\" \/><\/figure>\n\n\n\n<p>\u7b49\u3057\u3044\u3068\u5224\u5b9a\u3055\u308c\u307e\u3057\u305f\u3002<br><br>\u3053\u308c\u306f\u3069\u3046\u3044\u3046\u3053\u3068\u304b\u3068\u3044\u3046\u3068\u3001<span class=\"marker\">Java\u3067\u306f\u4f59\u8a08\u306a<\/span><span class=\"marker\">\u30e1\u30e2\u30ea<\/span><span class=\"marker\">\u5bb9\u91cf\u3092\u4f7f\u308f\u305a\u306b\u6e08\u3080\u3088\u3046\u306b\u3001\u540c\u3058\u5024\u3092\u5b9a\u7fa9\u3057\u305f\u5909\u6570\u306f\u540c\u3058\u30a2\u30c9\u30ec\u30b9\u3092\u6307\u3059\u3088\u3046\u306b\u3057\u3066\u3044\u308b<\/span>\u305f\u3081\u3067\u3059\u3002<br><br><br>\u6b21\u306b\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u66f8\u304d\u65b9\u3092\u5909\u3048\u3066\u6bd4\u8f03\u3057\u3066\u307f\u308b\u3053\u3068\u306b\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>\t\/\/\u6587\u5b57\u5217\u540c\u58eb\u3092\u6bd4\u8f03\u3059\u308b\n\tpublic void CompareStr2Str2() {\n\t\tString str1 = &quot;apple&quot;;\n\t\tString str2 = &quot;&quot;+ &quot;apple&quot;;\n\t\t\/\/\u901a\u5e38\u306e\u7b49\u53f7\u3067\u6bd4\u8f03\u3057\u3066\u307f\u308b\uff08\u7b49\u53f7\u306e\u52d5\u4f5c\u304c\u6b63\u3057\u3051\u308c\u3070\u300c\u7b49\u3057\u3044\u300d\u3068\u8868\u793a\u3055\u308c\u308b\uff09\n\t\tif(str1 == str2) {\n\t\t\tSystem.out.println(&quot;\u7b49\u3057\u3044&quot;);\n\t\t} else {\n\t\t\tSystem.out.println(&quot;\u7b49\u3057\u304f\u306a\u3044&quot;);\n\t\t}\n\t}<\/code><\/pre><\/div>\n\n\n\n<p>\u7d50\u679c\u3092\u898b\u3066\u307f\u307e\u3059\u3068\u30fb\u30fb<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"805\" height=\"265\" src=\"https:\/\/se-pg-toolbox.com\/wp-content\/uploads\/2023\/12\/article10-3.png\" alt=\"\u6587\u5b57\u5217\u540c\u58eb\u306e==\u306b\u3088\u308b\u6bd4\u8f032\" class=\"wp-image-168\" \/><\/figure>\n\n\n\n<p>\u3084\u306f\u308a\u7b49\u3057\u3044\u3068\u7d50\u679c\u304c\u51fa\u307e\u3057\u305f\u3002<br><br>\u5b9a\u7fa9\u306e\u6bb5\u968e\u3067\u6587\u5b57\u5217\u3092\u7d50\u5408\u3057\u3066\u3082\u6700\u7d42\u7684\u306b\u306fstr1\u3068str2\u3067\u540c\u3058&#8221;apple&#8221;\u3068\u3044\u3046\u6587\u5b57\u5217\u3092\u5b9a\u7fa9\u3057\u305f\u3053\u3068\u306b\u306a\u308b\u305f\u3081\u3001\u540c\u3058\u30a2\u30c9\u30ec\u30b9\u3092\u53c2\u7167\u3059\u308b\u3088\u3046\u306b\u306a\u308b\u3088\u3046\u3067\u3059\u3002<\/p>\n\n\n\n<p><br>\u6b21\u306b2\u3064\u306e\u6587\u5b57\u5217\u3092\u5b9a\u7fa9\u3059\u308b\u5909\u6570\u306e\u7247\u65b9\u306e\u30a2\u30c9\u30ec\u30b9\u3092\u610f\u56f3\u7684\u306b\u5909\u3048\u3066==\u3067\u5224\u5b9a\u3059\u308b\u3068\u3069\u3046\u306a\u308b\u304b\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>\t\/\/\u6587\u5b57\u5217\u540c\u58eb\u3092\u6bd4\u8f03\u3059\u308b\n\tpublic void CompareStr2Str3() {\n\t\tString str1 = &quot;apple&quot;;\n\t\tString str2 = new String(&quot;apple&quot;);\n\t\t\/\/\u901a\u5e38\u306e\u7b49\u53f7\u3067\u6bd4\u8f03\u3057\u3066\u307f\u308b\uff08\u7b49\u53f7\u306e\u52d5\u4f5c\u304c\u6b63\u3057\u3051\u308c\u3070\u300c\u7b49\u3057\u304f\u306a\u3044\u300d\u3068\u8868\u793a\u3055\u308c\u308b\uff09\n\t\tif(str1 == str2) {\n\t\t\tSystem.out.println(&quot;\u7b49\u3057\u3044&quot;);\n\t\t} else {\n\t\t\tSystem.out.println(&quot;\u7b49\u3057\u304f\u306a\u3044&quot;);\n\t\t}\n\t}<\/code><\/pre><\/div>\n\n\n\n<p>\u7d50\u679c\u3092\u898b\u3066\u307f\u307e\u3059\u3068\u30fb\u30fb<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"798\" height=\"253\" src=\"https:\/\/se-pg-toolbox.com\/wp-content\/uploads\/2023\/12\/article10-4.png\" alt=\"\u6587\u5b57\u5217\u540c\u58eb\u306e==\u306b\u3088\u308b\u6bd4\u8f033\" class=\"wp-image-169\" \/><\/figure>\n\n\n\n<p>\u4eca\u5ea6\u306f\u7b49\u3057\u304f\u306a\u3044\u3068\u3044\u3046\u7d50\u679c\u304c\u51fa\u307e\u3057\u305f\u3002<br><br>str1\u3082str2\u3082\u540c\u3058&#8221;apple&#8221;\u3068\u3044\u3046\u6587\u5b57\u5217\u3067\u5b9a\u7fa9\u3057\u3066\u3044\u308b\u306e\u3067\u3059\u304c\u3001\u30a2\u30c9\u30ec\u30b9\u304c\u9055\u3046\u305f\u3081\u7b49\u3057\u304f\u306a\u3044\u3068\u5224\u5b9a\u3055\u308c\u3066\u3044\u307e\u3059\u3002<br><br>\u3067\u306f\u3001\u7570\u306a\u308b\u30a2\u30c9\u30ec\u30b9\u306e\u6587\u5b57\u5217\u3092\u6bd4\u8f03\u3059\u308b\u306b\u306f\u3069\u3046\u3059\u308c\u3070\u3044\u3044\u3067\u3057\u3087\u3046\u304b\uff1f<br><br>\u6b21\u306e\u7ae0\u3067\u8aac\u660e\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u6587\u5b57\u5217\u540c\u58eb\u306e\u6bd4\u8f03\u306fequals()\u3092\u4f7f\u3046<\/h2>\n\n\n\n<p>\u7570\u306a\u308b\u30a2\u30c9\u30ec\u30b9\u306e\u6587\u5b57\u5217\u306e\u5024\u3092\u6bd4\u8f03\u3059\u308b\u5834\u5408\u306f\u3001\u540c\u3058\u5024\u3067\u3042\u3063\u3066\u3082==\u3067\u6bd4\u8f03\u3059\u308b\u3068\u7b49\u3057\u304f\u306a\u3044\u3068\u5224\u5b9a\u3055\u308c\u308b\u3053\u3068\u304c\u524d\u306e\u7ae0\u3067\u304a\u5206\u304b\u308a\u3044\u305f\u3060\u3051\u305f\u304b\u3068\u601d\u3044\u307e\u3059\u3002<br><br>\u3067\u306f\u3001\u7570\u306a\u308b\u30a2\u30c9\u30ec\u30b9\u306e\u6587\u5b57\u5217\u3067\u5024\u304c\u7b49\u3057\u3044\u304b\u3069\u3046\u304b\u3092\u5224\u5b9a\u3059\u308b\u5834\u5408\u3001\u3069\u3046\u3059\u308c\u3070\u3044\u3044\u3067\u3057\u3087\u3046\u304b\uff1f<br><br>\u7d50\u8ad6\u304b\u3089\u5148\u306b\u7533\u3057\u4e0a\u3052\u308b\u3068equals()\u306b\u3088\u308a\u5224\u5b9a\u3057\u307e\u3059\u3002<br><br>\u69cb\u6587\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p><mark class=\"has-inline-color has-vivid-cyan-blue-color\"><strong>\u6bd4\u8f03\u3057\u305f\u3044\u6587\u5b57\u5217\u306e\u5909\u65701.<\/strong><\/mark><mark class=\"has-inline-color has-luminous-vivid-orange-color\"><strong>equals(<\/strong><\/mark><mark class=\"has-inline-color has-vivid-purple-color\"><strong>\u6bd4\u8f03\u3057\u305f\u3044\u6587\u5b57\u5217\u306e\u5909\u65702<\/strong><\/mark><mark class=\"has-inline-color has-luminous-vivid-orange-color\"><strong>)<\/strong><\/mark><br><br>\u305f\u3068\u3048\u3070\u3001\u5148\u307b\u3069\u7b49\u3057\u304f\u306a\u3044\u3068\u5224\u5b9a\u3055\u308c\u305fif\u6587\u3092equals()\u3092\u7528\u3044\u3066\u66f8\u304d\u63db\u3048\u308b\u3068\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>\t\/\/\u6587\u5b57\u5217\u540c\u58eb\u3092\u6bd4\u8f03\u3059\u308b\n\tpublic void CompareStr2Str4() {\n\t\tString str1 = &quot;apple&quot;;\n\t\tString str2 = new String(&quot;apple&quot;);\n\t\t\/\/equals\u3067\u6bd4\u8f03\u3057\u3066\u307f\u308b\uff08\u7b49\u53f7\u306e\u52d5\u4f5c\u304c\u6b63\u3057\u3051\u308c\u3070\u300c\u7b49\u3057\u3044\u300d\u3068\u8868\u793a\u3055\u308c\u308b\uff09\n\t\tif(str1.equals(str2)) {\n\t\t\tSystem.out.println(&quot;\u7b49\u3057\u3044&quot;);\n\t\t} else {\n\t\t\tSystem.out.println(&quot;\u7b49\u3057\u304f\u306a\u3044&quot;);\n\t\t}\n\t}<\/code><\/pre><\/div>\n\n\n\n<p>\u3053\u306e\u51e6\u7406\u3092\u5b9f\u884c\u3057\u3066\u307f\u308b\u3068\u30fb\u30fb\u30fb<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"799\" height=\"262\" src=\"https:\/\/se-pg-toolbox.com\/wp-content\/uploads\/2023\/12\/article10-5.png\" alt=\"\u6587\u5b57\u5217\u540c\u58eb\u306eequals()\u306b\u3088\u308b\u6bd4\u8f03\" class=\"wp-image-170\" \/><\/figure>\n\n\n\n<p>\u6b63\u3057\u304f\u7b49\u3057\u3044\u3068\u5224\u5b9a\u3055\u308c\u307e\u3057\u305f\u3002<br><br>\u305f\u3060\u3057\u3001\u3053\u306eequals()\u3067\u3059\u304c\u3001\u6c17\u3092\u4ed8\u3051\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002<br><br>\u305d\u308c\u306f<span class=\"marker2\">equals()\u3092\u3064\u3051\u308b\u5909\u6570\u306e\u5024\u304cnull\u3067\u3042\u308c\u3070\u6bd4\u8f03\u304c\u51fa\u6765\u305a\u3001\u30a8\u30e9\u30fc\u3068\u306a\u3063\u3066\u3057\u307e\u3046<\/span>\u3053\u3068\u3067\u3059\u3002<br><br>\u4f8b\u3048\u3070\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u6bd4\u8f03\u3092\u3057\u3066\u307f\u308b\u3053\u3068\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>\t\/\/\u6587\u5b57\u5217\u3068null\u3092\u6bd4\u8f03\u3059\u308b\n\tpublic void CompareStr2Str5() {\n\t\tString str1 = &quot;apple&quot;;\n\t\tString str2 = null;\n\t\t\/\/equals\u3067\u6bd4\u8f03\u3057\u3066\u307f\u308b\uff08null\u30dd\u30a4\u30f3\u30bf\u4f8b\u5916\u767a\u751f\uff09\n\t\tif(str2.equals(str1)) {\n\t\t\tSystem.out.println(&quot;\u7b49\u3057\u3044&quot;);\n\t\t} else {\n\t\t\tSystem.out.println(&quot;\u7b49\u3057\u304f\u306a\u3044&quot;);\n\t\t}\n\t}<\/code><\/pre><\/div>\n\n\n\n<p>str2\u304cnull\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u304c\u3001\u3069\u3046\u306a\u308b\u3067\u3057\u3087\u3046\u304b\uff1f<\/p>\n\n\n\n<p>\u7d50\u679c\u3068\u3057\u3066\u306f\u4ee5\u4e0b\u306e\u30a8\u30e9\u30fc\u304c\u51fa\u3066\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u505c\u6b62\u3057\u3066\u3057\u307e\u3044\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><mark class=\"has-inline-color has-vivid-red-color\">Exception in thread \"main\" java.lang.NullPointerException: Cannot invoke \"String.equals(Object)\" because \"str2\" is null\r\n\tat article10.Compare.CompareStr2Str5(Compare.java:58)\r\n\tat article10.Main.main(Main.java:9)<\/mark>\n<\/pre>\n\n\n\n<p>  <br>str2\u304cnull\u3067\u3042\u308b\u305f\u3081\u3001nullPointerException\uff08\u30dd\u30a4\u30f3\u30bf\u3092\u6307\u3059\u5148\u304cnull\u306b\u306a\u3063\u3066\u53c2\u7167\u3067\u304d\u306a\u3044\u5834\u5408\u306b\u767a\u751f\u3059\u308b\u4f8b\u5916\uff09\u304c\u8d77\u304d\u3066\u3057\u307e\u3044\u307e\u3057\u305f\u3002<br><br>nullPointerException\u306fequals()\u3092\u4f7f\u3046\u3068\u3088\u304f\u898b\u308b\u4f8b\u5916\u3067\u3001\u3053\u306e\u4f8b\u5916\u3092\u9632\u3050\u305f\u3081\u306b\u306fequals()\u3092\u3064\u3051\u308b\u5909\u6570\uff08\u4e0a\u8a18\u30bd\u30fc\u30b9\u3067\u306fstr2\u304c\u8a72\u5f53\u3057\u307e\u3059\uff09\u304cnull\u306b\u306a\u3089\u306a\u3044\u3088\u3046\u3001\u5fc5\u305a\u5024\u304c\u5165\u308b\u72b6\u614b\u306b\u3057\u3066\u304a\u304b\u306a\u3051\u308c\u3070\u306a\u308a\u307e\u305b\u3093\u3002<br><br>\u306a\u304a\u3001if(str2.equals(str1))\u306e\u90e8\u5206\u3092if(str1.equals(str2))\u306b\u66f8\u304d\u63db\u3048\u3066\u3001equals()\u306e\u5f15\u6570\u306e\u6587\u5b57\u5217\u304cnull\u306b\u306a\u308b\u5834\u5408\u306f\u6b63\u3057\u304f\u300c\u7b49\u3057\u304f\u306a\u3044\u300d\u3068\u5224\u5b9a\u3055\u308c\u307e\u3059\u304c\u3001\u3053\u3061\u3089\u3082\u4f8b\u5916\u306f\u8d77\u3053\u3089\u306a\u3044\u3082\u306e\u306e\u3001\u3042\u307e\u308a\u597d\u307e\u3057\u3044\u6bd4\u8f03\u65b9\u6cd5\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002<br><br>\u6bd4\u8f03\u3092\u884c\u3063\u305f\u5f8c\u306b\u4ed6\u306e\u30b3\u30fc\u30c9\u304c\u66f8\u3044\u3066\u3042\u308c\u3070\u3001\u305d\u3053\u3067\u5f15\u3063\u304b\u304b\u3063\u3066nullPointerException\u304c\u51fa\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002<br><br><span class=\"marker\">\u6587\u5b57\u5217\u3092equals\u3092\u4f7f\u3063\u3066\u6bd4\u8f03\u3059\u308b\u5834\u5408\u306f\u5909\u6570\u304cnull\u3067\u306a\u3044\u3053\u3068\u3092\u304d\u3061\u3093\u3068\u4e8b\u524d\u306b\u30c1\u30a7\u30c3\u30af\u3057\u3001null\u304c\u5165\u3089\u306a\u3044\u72b6\u614b\u3067equals()\u3092\u4f7f\u3046<\/span>\u306a\u3069\u306e\u914d\u616e\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u6587\u5b57\u5217\u3068null\u306e\u6bd4\u8f03\u65b9\u6cd5<\/h2>\n\n\n\n<p>\u524d\u7bc0\u306e\u8a71\u306e\u5185\u5bb9\u3060\u3051\u3060\u3068\u3001\u6587\u5b57\u5217\u304cnull\u3067\u3042\u308b\u304b\u3069\u3046\u304b\u306e\u5224\u5b9a\u306f\u3069\u3046\u3059\u308c\u3070\u3044\u3044\u306e\u304b\u3068\u7591\u554f\u306b\u601d\u3046\u65b9\u3082\u3044\u308b\u3067\u3057\u3087\u3046\u3002<br><br>\u7b54\u3048\u306f\u5358\u7d14\u3067<span class=\"marker\">\u6587\u5b57\u5217\u3068null\u306e\u6bd4\u8f03\u306f\u7c21\u5358\u3067\u3001==\u3092\u4f7f\u3063\u3066\u6bd4\u8f03\u3092\u3059\u308b<\/span>\u3060\u3051\u3067\u3059\u3002<br><br>\u4f8b\u3048\u3070\u4ee5\u4e0b\u306e\u51e6\u7406\u3092\u5b9f\u884c\u3057\u3066\u307f\u308b\u3053\u3068\u306b\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>\t\/\/\u6587\u5b57\u5217\u3068null\u3092\u6bd4\u8f03\u3059\u308b\n\tpublic void CompareStr2Str6() {\n\t\tString str1 = null;\n\t\t\/\/null\u304c\u5165\u3063\u305f\u5909\u6570\u3092\u901a\u5e38\u306e\u7b49\u53f7\u3067\u6bd4\u8f03\u3057\u3066\u307f\u308b\u3002\u7b49\u53f7\u306e\u52d5\u4f5c\u304c\u6b63\u3057\u3051\u308c\u3070\u300c\u7b49\u3057\u3044\u300d\u3068\u8868\u793a\u3055\u308c\u308b\uff09\n\t\tif(str1 == null) {\n\t\t\tSystem.out.println(&quot;\u7b49\u3057\u3044&quot;);\n\t\t} else {\n\t\t\tSystem.out.println(&quot;\u7b49\u3057\u304f\u306a\u3044&quot;);\n\t\t}\n\t}<\/code><\/pre><\/div>\n\n\n\n<p>\u4e0a\u8a18\u306e\u51e6\u7406\u3092\u5b9f\u884c\u3057\u3066\u307f\u308b\u3068\u30fb\u30fb\u30fb<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"796\" height=\"247\" src=\"https:\/\/se-pg-toolbox.com\/wp-content\/uploads\/2023\/12\/article10-6.png\" alt=\"\u5909\u6570\u304cnull\u3067\u3042\u308b\u304b\u3069\u3046\u304b\u306e\u5224\u5b9a\" class=\"wp-image-171\" \/><\/figure>\n\n\n\n<p>\u304d\u3061\u3093\u3068\u7b49\u3057\u3044\u3068\u5224\u5b9a\u3055\u308c\u307e\u3057\u305f\u3002<br><br>\u3053\u306enull\u3067\u3042\u308b\u304b\u306e\u5224\u5b9a\u306fJava\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u66f8\u304f\u969b\u306f\u826f\u304f\u4f7f\u3046\u3053\u3068\u306b\u306a\u308b\u305f\u3081\u3001\u3057\u3063\u304b\u308a\u3068\u899a\u3048\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u307e\u3068\u3081<\/h2>\n\n\n\n<p>\u4eca\u56de\u8aac\u660e\u3057\u305f\u5185\u5bb9\u3092\u307e\u3068\u3081\u307e\u3059\u3002<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u6570\u5024\u540c\u58eb\u306e\u6bd4\u8f03\u306f==\u3092\u4f7f\u3063\u3066\u554f\u984c\u306a\u3044<\/li>\n\n\n\n<li>\u6587\u5b57\u5217\u540c\u58eb\u306e\u6bd4\u8f03\u306f\u539f\u5247\u3068\u3057\u3066equlas()\u3092\u4f7f\u3046<\/li>\n\n\n\n<li>equals()\u3092\u4ed8\u3051\u308b\u5909\u6570\u306e\u5024\u304cnull\u3067\u3042\u308c\u3070\u4f8b\u5916\u304c\u767a\u751f\u3059\u308b\u306e\u3067\u3001\u5fc5\u305anull\u306b\u306a\u3089\u306a\u3044\u3088\u3046\u306b\u8003\u616e\u3057\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u3002<\/li>\n\n\n\n<li>\u5909\u6570\u3068null\u3068\u306e\u6bd4\u8f03\u306f==\u3067\u6bd4\u8f03\u304c\u53ef\u80fd\u3067\u3042\u308b<\/li>\n<\/ol>\n\n\n\n<p>\u3069\u308c\u3082\u57fa\u672c\u7684\u306a\u3053\u3068\u3067\u306f\u3042\u308a\u307e\u3059\u304c\u3001<span class=\"marker2\">\u6587\u5b57\u5217\u540c\u58eb\u306e\u6bd4\u8f03\u3067==\u3092\u4f7f\u3063\u3066\u3057\u307e\u3046\u3068\u3001\u671f\u5f85\u3057\u305f\u52d5\u4f5c\u306b\u306a\u3089\u306a\u3044\u3053\u3068\u304c\u591a\u304f\u3001\u30d0\u30b0\u3092\u751f\u307f\u51fa\u3059\u539f\u56e0\u3068\u306a\u308a\u307e\u3059<\/span>\u3002<br><br>\u3067\u3059\u306e\u3067\u3001Java\u3067\u6587\u5b57\u5217\u540c\u58eb\u306e\u6bd4\u8f03\u3092\u884c\u3046\u306e\u3067\u3042\u308c\u3070\u3001\u5fc5\u305aequals()\u3092\u4f7f\u3063\u3066\u6bd4\u8f03\u3059\u308b\u3088\u3046\u306b\u7fd2\u6163\u3065\u3051\u3066\u307b\u3057\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p><span class=\"marker\">\u4eca\u56de\u306e\u8a18\u4e8b\u306f\u3053\u3053\u307e\u3067\u3068\u306a\u308a\u307e\u3059\u3002<br>\u307e\u305f\u6b21\u56de\u306e\u8a18\u4e8b\u3067\u304a\u4f1a\u3044\u3057\u307e\u3057\u3087\u3046\u3002<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u56de\u306fJava\u3092\u4f7f\u3046\u6642\u306b\u3001\u521d\u5fc3\u8005\u304c\u30df\u30b9\u3092\u72af\u3057\u3084\u3059\u3044==\u306e\u7b49\u53f72\u3064\u306e\u6bd4\u8f03\u306b\u3064\u3044\u3066\u304a\u8a71\u3057\u3057\u307e\u3059\u3002 \u57fa\u672c\u7684\u306b\u6587\u5b57\u5217\u306e\u6bd4\u8f03\u3067==\u3092\u4f7f\u3063\u3066\u306f\u3044\u3051\u306a\u3044\u3053\u3068\u3092\u7406\u89e3\u3057\u3066\u304a\u3051\u3070\u5341\u5206\u3067\u3059\u304c\u3001\u9593\u9055\u3063\u3066\u4f7f\u3063\u3066\u3057\u307e\u3063\u305f\u5834\u5408\u3082\u666e\u901a\u306b\u6b63\u3057\u3044\u6bd4\u8f03\u304c\u51fa\u6765<\/p>\n","protected":false},"author":2,"featured_media":160,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jin_ogp_image_url":"","_jin_last_featured_id":0,"footnotes":""},"categories":[9,5],"tags":[15,4],"class_list":["post-165","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","category-5","tag-java","tag-4"],"_links":{"self":[{"href":"https:\/\/se-pg-toolbox.com\/index.php?rest_route=\/wp\/v2\/posts\/165","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/se-pg-toolbox.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/se-pg-toolbox.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/se-pg-toolbox.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/se-pg-toolbox.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=165"}],"version-history":[{"count":3,"href":"https:\/\/se-pg-toolbox.com\/index.php?rest_route=\/wp\/v2\/posts\/165\/revisions"}],"predecessor-version":[{"id":179,"href":"https:\/\/se-pg-toolbox.com\/index.php?rest_route=\/wp\/v2\/posts\/165\/revisions\/179"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/se-pg-toolbox.com\/index.php?rest_route=\/wp\/v2\/media\/160"}],"wp:attachment":[{"href":"https:\/\/se-pg-toolbox.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=165"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/se-pg-toolbox.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=165"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/se-pg-toolbox.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}