Introduction to String - The Coding Shala
Home >> Data Structures >> Introduction to String Introduction to String A String is a collection of Unicode characters and similar to the arrays. We can perform almost all the operations on the string that we used in an array. Below is some function that we use frequently with Strings. Compare Function The String has its own compare function, unlike the == operator. We can compare two strings in the following ways: we can use == operator, like string1 == string2. we can use equals() method. like string1.equals(string). we can use compareTo() method. For example string1.compareTo(string2). Note: The equals() method compares the value inside string while == operator compares the value of two object references to check if they refer to the same String instance or not. Both equals() and == returns true and false. The Java String compareTo() method is used for comparing two string lexicographically. If both the strings are the same the...