خلاصه مطلب
در این آموزش قصد داریم در مورد متدهای ()equals و ()equalsIgnoreCase باهم بحث کنیم. هر دو متد برای مقایسه دو رشته(String) در جاوا کاربرد دارند.
نوع محتوامقاله آموزشی
موضوعآموزش برنامه نویسی »
زمان مطالعه۱ دقیقه
آخرین ویرایش۵ آبان ۱۳۹۶
جاوا
.png)
کانال تلگرام جاوا 
دانلود کتاب آموزش جاوا لینک دانلود
| boolean equals(String str): |
| boolean equalsIgnoreCase(String str): |
| package javalike;public class EqualsExample1 { 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")); } } |
| str1 equals to str2:false str1 equals to str3:true str1 equals to Welcome:false str1 equals to Hello:true str1 equals to hello:false |
| package javalike;public class EqualsExample2 { 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")); } } |
| str1 equals to str2:falsestr1 equals to str3:true str1 equals to Welcome:false str1 equals to Apple:true str2 equals to mango:true |
.png)


