- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 9321 Articles for Object Oriented Programming
2K+ Views
The equals() method compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.Example Live Demopublic class Sample { public static void main(String []args) { String s1 = "tutorialspoint"; String s2 = "tutorialspoint"; String s3 = new String ("Tutorials Point"); System.out.println(s1.equals(s2)); System.out.println(s2.equals(s3)); } }Outputtrue falseYou can also compare two strings using == operator. But, it compares references of the given ... Read More
245 Views
You can compare two Strings in Java using the compareTo() method, equals() method or == operator.The compareTo() method compares two strings. The comparison is based on the Unicode value of each character in the strings. The character sequence represented by this String object is compared lexicographically to the character sequence represented by the argument string. The result is a negative integer if this String object lexicographically precedes the argument string.The result is a positive integer if this String object lexicographically follows the argument string. The result is zero if the strings are equal, compareTo returns 0 exactly when the equals(Object) method would ... Read More
1K+ Views
We all know that the String class in Java is mutable i.e. once we create a String variable we cannot modify its data or do any manipulations.But, there may be scenarios where we need to modify the data of String variables. In such cases, we could use StringBuffer class.This class −is like a String, but can be modified. It contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls.Is safe for use by multiple threads.
2K+ Views
The compareTo() method compares two strings lexicographically. The comparison is based on the Unicode value of each character in the strings. The character sequence represented by this String object is compared lexicographically to the character sequence represented by the argument string.The result is a negative integer if this String object lexicographically precedes the argument string. The result is a positive integer if this String object lexicographically follows the argument string. The result is zero if the strings are equal, compareTo returns 0 exactly when the equals(Object) method would return true.ExampleLive Demopublic class StringDemo { public static void main(String[] args) { ... Read More
15K+ Views
You can check the equality of two Strings in Java using the equals() method. This method compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.Exampleimport java.lang.* public class StringDemo { public static void main(String[] args) { String str1 = "Tutorialspoint"; String str2 = "Tutorialspoint"; String str3 = "Hi"; // checking for equality boolean retval1 = ... Read More
283 Views
The equals() methodThis method compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.Exampleimport java.lang.*; public class StringDemo { public static void main(String[] args) { String str1 = "sachin tendulkar"; String str2 = "amrood admin"; String str3 = "amrood admin"; // checking for equality boolean retval1 = str2.equals(str1); boolean retval2 = str2.equals(str3); ... Read More
117 Views
The compareTo() method in Java compares two strings lexicographically.ExampleLive Demopublic class Test { public static void main(String args[]) { String str1 = "Strings are immutable"; String str2 = new String("Strings are immutable"); String str3 = new String("Integers are not immutable"); int result = str1.compareTo( str2 ); System.out.println(result); result = str2.compareTo( str3 ); System.out.println(result); } }Output0 10
282 Views
You can compare two Strings in Java using the compareTo() method, equals() method or == operator.The compareTo() method compares two strings. The comparison is based on the Unicode value of each character in the strings. The character sequence represented by this String object is compared lexicographically to the character sequence represented by the argument string.The result is a negative integer if this String object lexicographically precedes the argument string.The result is a positive integer if this String object lexicographically follows the argument string.The result is zero if the strings are equal, compareTo returns 0 exactly when the equals(Object) method would ... Read More
235 Views
You can check the equality of two Strings in Java using the equals() method. This method compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.Exampleimport java.lang.* public class StringDemo { public static void main(String[] args) { String str1 = "Tutorialspoint"; String str2 = "Tutorialspoint"; String str3 = "Hi"; // checking for equality boolean retval1 = ... Read More
541 Views
The equals() method compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.Examplepublic class Sample{ public static void main(String []args){ String s1 = "tutorialspoint"; String s2 = "tutorialspoint"; String s3 = new String ("Tutorials Point"); System.out.println(s1.equals(s2)); System.out.println(s2.equals(s3)); } }Outputtrue falseYou can also compare two strings using == operator. But, it compares references of the given variables not values.Examplepublic class ... Read More