BOOKJAVA Telegram 3937
В чём разница между == и .equals() при сравнении строк?

== сравнивает ссылки на объекты (адреса в памяти), а .equals() сравнивает содержимое строк. Для сравнения строк всегда используйте .equals().

Вот пример, иллюстрирующий разницу:


String str1 = "Hello";
String str2 = "Hello";
String str3 = new String("Hello");
System.out.println(str1 == str2); // true (один и тот же объект)
System.out.println(str1 == str3); // false (разные объекты)
System.out.println(str1.equals(str2)); // true (одинаковое содержимое)
System.out.println(str1.equals(str3)); // true (одинаковое содержимое)


👉@BookJava
👍7💩2



tgoop.com/BookJava/3937
Create:
Last Update:

В чём разница между == и .equals() при сравнении строк?

== сравнивает ссылки на объекты (адреса в памяти), а .equals() сравнивает содержимое строк. Для сравнения строк всегда используйте .equals().

Вот пример, иллюстрирующий разницу:


String str1 = "Hello";
String str2 = "Hello";
String str3 = new String("Hello");
System.out.println(str1 == str2); // true (один и тот же объект)
System.out.println(str1 == str3); // false (разные объекты)
System.out.println(str1.equals(str2)); // true (одинаковое содержимое)
System.out.println(str1.equals(str3)); // true (одинаковое содержимое)


👉@BookJava

BY Библиотека Java разработчика




Share with your friend now:
tgoop.com/BookJava/3937

View MORE
Open in Telegram


Telegram News

Date: |

How to Create a Private or Public Channel on Telegram? In the next window, choose the type of your channel. If you want your channel to be public, you need to develop a link for it. In the screenshot below, it’s ”/catmarketing.” If your selected link is unavailable, you’ll need to suggest another option. According to media reports, the privacy watchdog was considering “blacklisting” some online platforms that have repeatedly posted doxxing information, with sources saying most messages were shared on Telegram. How to Create a Private or Public Channel on Telegram? During the meeting with TSE Minister Edson Fachin, Perekopsky also mentioned the TSE channel on the platform as one of the firm's key success stories. Launched as part of the company's commitments to tackle the spread of fake news in Brazil, the verified channel has attracted more than 184,000 members in less than a month.
from us


Telegram Библиотека Java разработчика
FROM American