Telegram Group & Telegram Channel
Что выведет этот код на Java?


public class Main {
public static void main(String[] args) {
String a = "hello";
String b = "he" + "llo";
String c = "he";
String d = c + "llo";

System.out.println(a == b); // #1
System.out.println(a == d); // #2
System.out.println(a.equals(d)); // #3
}
}


🔢 Варианты ответа:

A)

true
true


B)

false
true


C)

false
true


D)

false
false


Правильный ответ: B

💡 Почему?
- Строки в Java — immutable и используют string pool.
-
a == btrue, потому что "he" + "llo" конкатенируется на этапе компиляции.
-
c + "llo" — создаёт новый объект во время выполнения.
-
a == dfalse, но a.equals(d)true, потому что .equals() сравнивает содержимое строк.

@javatg



tg-me.com/javatg/1802
Create:
Last Update:

Что выведет этот код на Java?


public class Main {
public static void main(String[] args) {
String a = "hello";
String b = "he" + "llo";
String c = "he";
String d = c + "llo";

System.out.println(a == b); // #1
System.out.println(a == d); // #2
System.out.println(a.equals(d)); // #3
}
}


🔢 Варианты ответа:

A)

true
true


B)

false
true


C)

false
true


D)

false
false


Правильный ответ: B

💡 Почему?
- Строки в Java — immutable и используют string pool.
-
a == btrue, потому что "he" + "llo" конкатенируется на этапе компиляции.
-
c + "llo" — создаёт новый объект во время выполнения.
-
a == dfalse, но a.equals(d)true, потому что .equals() сравнивает содержимое строк.

@javatg

BY Java


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/javatg/1802

View MORE
Open in Telegram


Java Telegram | DID YOU KNOW?

Date: |

A project of our size needs at least a few hundred million dollars per year to keep going,” Mr. Durov wrote in his public channel on Telegram late last year. “While doing that, we will remain independent and stay true to our values, redefining how a tech company should operate.

Can I mute a Telegram group?

In recent times, Telegram has gained a lot of popularity because of the controversy over WhatsApp’s new privacy policy. In January 2021, Telegram was the most downloaded app worldwide and crossed 500 million monthly active users. And with so many active users on the app, people might get messages in bulk from a group or a channel that can be a little irritating. So to get rid of the same, you can mute groups, chats, and channels on Telegram just like WhatsApp. You can mute notifications for one hour, eight hours, or two days, or you can disable notifications forever.

Java from it


Telegram Java
FROM USA