teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

3

追記の追記

2017/11/04 07:20

投稿

LouiS0616
LouiS0616

スコア35678

answer CHANGED
@@ -3,6 +3,8 @@
3
3
  if(Code.equals("1656")){
4
4
  ```
5
5
 
6
+ 追記
7
+ ---
6
8
  swordoneさんの回答と丸被りしてしまったので、ちょっと差別化を図ってみる。
7
9
  > **15.21.3. Reference Equality Operators == and !=**
8
10
  > [中略]

2

追記

2017/11/04 07:20

投稿

LouiS0616
LouiS0616

スコア35678

answer CHANGED
@@ -1,4 +1,11 @@
1
1
  文字列の比較には[String.equals](https://docs.oracle.com/javase/jp/8/docs/api/java/lang/String.html#equals-java.lang.Object-)を用いてください。
2
2
  ```Java
3
3
  if(Code.equals("1656")){
4
- ```
4
+ ```
5
+
6
+ swordoneさんの回答と丸被りしてしまったので、ちょっと差別化を図ってみる。
7
+ > **15.21.3. Reference Equality Operators == and !=**
8
+ > [中略]
9
+ > While == may be used to compare references of type String, such an equality test determines whether or not the two operands refer to the same String object. **The result is false if the operands are distinct String objects, even if they contain the same sequence of characters (§3.10.5).** The contents of two strings s and t can be tested for equality by the method invocation s.equals(t).
10
+
11
+ 引用元:[Java Language Specification - Chapter 15. Expressions](https://docs.oracle.com/javase/specs/jls/se9/html/jls-15.html#jls-15.21.3)、 **太字**は引用者による。

1

リンクの追加

2017/11/04 07:20

投稿

LouiS0616
LouiS0616

スコア35678

answer CHANGED
@@ -1,4 +1,4 @@
1
- 文字列の比較にはString.equalsを用いてください。
1
+ 文字列の比較には[String.equals](https://docs.oracle.com/javase/jp/8/docs/api/java/lang/String.html#equals-java.lang.Object-)を用いてください。
2
2
  ```Java
3
3
  if(Code.equals("1656")){
4
4
  ```