Академический Документы
Профессиональный Документы
Культура Документы
Java String Class is immutable,that means Strings in java, once created and initialized, cannot be changed on the same reference. A java.lang.String class is final which implies no class and extend it. The java.lang.String class differs from other classes, one difference being that the String objects can be used with the += and + operators for concatenation. Two useful methods for String objects are equals( ) and substring( ). The equals( ) method is used for testing whether two Strings contain the same value. The substring( ) method is used to obtain a selected portion of a String.
if (name1 == name3) { System.out.println("The strings are equal."); } else { System.out.println("The strings are unequal."); } } } ----------------------------------------------------------------------
Comparing using the equals Method -------------------------------------------------------------------------------------------The equals method is used when we need to compare the content of the text present in the String objects. This method returns true when two String objects hold the same content
public class First { {
public static void main(String[] args) String name1 = "Anuj"; String name2 = new String("Anuj"); String name3 = "Anuj";
if (name1.equals(name2)) { System.out.println("The strings are equal."); } else { System.out.println("The strings are unequal."); } if (name1.equals(name3)) { System.out.println("The strings are equal."); } else { System.out.println("The strings are unequal."); }}} ------------------------------------------------------------------------------------------------------