Мавзу: сатрлар


System.out.println(s1 + " equals " + s3 + " -> " + s1.equals(s3))


Download 0.54 Mb.
bet4/7
Sana08.06.2023
Hajmi0.54 Mb.
#1464427
1   2   3   4   5   6   7
Bog'liq
Maruza 4 JAVA String

System.out.println(s1 + " equals " + s3 + " -> " + s1.equals(s3));

  • System.out.println(s1 + " equals " + s3 + " -> " + s1.equals(s3));
  • System.out.println(s1 + " equals " + s4 + " -> " + s1.equals(s4));
  • System.out.println(s1 + " equalsIgnoreCase " + s4 + " -> " +
  • s1.equalsIgnoreCase(s4));
  • } }
  • Dastur bajarish natijasi:
  • С:\> java equalsDemo
  • Hello equals Hello -> true
  • Hello equals Good-bye -> false
  • Hello equals HELLO -> false
  • Hello equalsIgnoreCase HELLO -> true

Dastur bajarish natijasi:

5. Tenglik usuli (equals())

  • 5. Tenglik usuli (equals())
  • Satrlarni solishtirishda equals usuli va operator == turli tekshirishni amalga oshiradi. Аgar equal usuli simvollarni satr ichida solishtirsa operator == obʼektlarga koʼrsatkichlarni solishtiradi va ular bir xil obʼektga ilova qilayotganligini tekshiradi. Quyidagi misolda satrlar bir xil boʼlgani bilan, turli obʼektlar boʼlgani uchun equals va == turli natijalarni beradi.
  • class EqualsNotEqualTo {
  • public static void main(String args[]) {
  • String s1 = "Hello";
  • String s2 = new String(s1);
  • System.out.println(s1 + " equals " + s2 + " -> " + s1.equals(s2));
  • System.out.println(s1 + " == " + s2 + ", -> " + (s1 == s2));
  • } }

Download 0.54 Mb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling