What is the difference between the String#equals method and the String#contentEquals method?
String#equals
String#contentEquals
The String#equals() not only compares the String's contents, but also checks if the other object is also an instance of a String. The String#contentEquals() only compares the contents (the character sequence) and does not check if the other object is also an instance of String. It can be anything as long as it is an implementation of CharSequence which covers a.o. String, StringBuilder, StringBuffer, CharBuffer, etc.
String#equals()
String
String#contentEquals()
CharSequence
StringBuilder
StringBuffer
CharBuffer
1.4m articles
1.4m replys
5 comments
56.9k users