<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # Java String`equals()`和`equalsIgnoreCase()`方法 > 原文: [https://beginnersbook.com/2013/12/java-string-equals-and-equalsignorecase-methods-example/](https://beginnersbook.com/2013/12/java-string-equals-and-equalsignorecase-methods-example/) 在本教程中,我們將討論`equals()`和`equalsIgnoreCase()`方法。這兩種方法都用于比較兩個字符串。它們之間的唯一區別是`equals()`方法考慮了大小寫,而`equalsIgnoreCase()`方法在比較期間忽略了大小寫。對于例如如果我們比較字符串`"TEXT"`和`"text"`,`equals()`方法將返回`false`,但`equalsIgnoreCase()`將返回`true`。 `boolean equals(String str)`:區分大小寫 `boolean equalsIgnoreCase(String str)`:不區分大小寫 ## Java `String equals()`方法示例 在這個例子中,我們將看到`equals()`方法在不同場景中的工作原理。我們可以使用`equals()`方法比較兩個`String`實例(`str1`,`str2`,`str3`),就像我們在下面的例子中所做的那樣,或者我們也可以比較字符串實例和作為參數傳遞給`equals()`方法的硬編碼字符串,如以下示例。 您可以在輸出中觀察到,當我們將`String str1`(值`"Hello"`)與字符串`"hello"`進行比較時,`equals()`方法返回`false`,因為此方法區分大小寫并在比較字符串時考慮了大小寫。另一方面,`equalsIgnoreCase()`方法在忽略它們的情況時比較字符串,我們將在下一節中看到。 ```java public class JavaExample{ public static void main(String args[]){ String str1= new String("Hello"); String str2= new String("Hi"); String str3= new String("Hello"); System.out.println("str1 equals to str2:"+str1.equals(str2)); System.out.println("str1 equals to str3:"+str1.equals(str3)); System.out.println("str1 equals to Welcome:"+str1.equals("Welcome")); System.out.println("str1 equals to Hello:"+str1.equals("Hello")); System.out.println("str1 equals to hello:"+str1.equals("hello")); } } ``` **輸出:** ![Java equals method example](https://img.kancloud.cn/17/2e/172ef5c97e02f731258e5585187ba76e_1024x657.jpg) ## Java `String equalsIgnoreCase()`方法示例 方法`equalsIgnoreCase()`在比較兩個字符串時忽略大小寫。在下面的示例中,我們將字符串`"Apple"`與字符串`"APPLE"`進行了比較,并返回`true`。 ```java public class JavaExample{ public static void main(String args[]){ String str1= new String("Apple"); String str2= new String("MANGO"); String str3= new String("APPLE"); System.out.println("str1 equals to str2:"+str1.equalsIgnoreCase(str2)); System.out.println("str1 equals to str3:"+str1.equalsIgnoreCase(str3)); System.out.println("str1 equals to Welcome:"+str1.equalsIgnoreCase("Welcome")); System.out.println("str1 equals to Apple:"+str1.equalsIgnoreCase("Apple")); System.out.println("str2 equals to mango:"+str2.equalsIgnoreCase("mango")); } } ``` **輸出:** ![Java equalsIgnoreCase() method example](https://img.kancloud.cn/00/2a/002a6df1a413da7178c7756c67a529b2_1024x606.jpg)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看