String#equals和String#contentEquals方法之间的区别 [英] Difference between String#equals and String#contentEquals methods
问题描述
String#equals
方法和 字符串#contentEquals
方法?
推荐答案
String#equals()
不仅要比较String的内容,还要检查另一个对象是否也是一个实例一个字符串
。 String#contentEquals()
仅比较内容(字符序列)并不检查另一个对象是否也是<$的实例C $ C>字符串。它可以是任何东西,只要它是 <的实现。 code> CharSequence ,涵盖了ao String
, StringBuilder
, StringBuffer
, CharBuffer
等。
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#contentEquals方法之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!