Java String Compare with == and equals( ).

Опубликовано: 27 Сентябрь 2015
на канале: DASARI TUTS
1,366
7

String is a class built into the Java language defined in the java.lang package. It represents character strings. Strings are ubiquitous in Java. Study the String class and its methods carefully. It will serve you well to know how to manipulate them skillfully. String literals in Java programs, such as "abc", are implemented as instances of this class like this:

EX:- String str = "This is string literal";

The method equals(String other) returns true if the string passed as a parameter is equal by content (this is the correct operation to test strings for equality). The similar method equalsIgnoreCase(String other) performs case insensitive comparison. The method hashCode() computes the numeric value that depends on the string content. The different strings most often have different hashcodes but in some corner cases may happen that they have the same. However two strings with the same content never have different hashcodes. Hashcode is used when implementing various advanced algorithms on strings.

As String implements hashCode() and equals() properly, it is possible to have structures like HashMap or HashSet of strings. The set will not store duplicate entries and the map will always find a key that matches the passed key string by content.


На этой странице сайта вы можете посмотреть видео онлайн Java String Compare with == and equals( ). длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь DASARI TUTS 27 Сентябрь 2015, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 1,366 раз и оно понравилось 7 зрителям. Приятного просмотра!