Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong><code>contentEquals(CharSequence cs)</code>:</strong></p> <ul> <li>Lets you check equality of given string value with any implementation instance of interface <code>java.lang.CharacterSequence</code> (eg, <code>CharBuffer</code>, <code>Segment</code>, <code>String</code>, <code>StringBuffer</code>, <code>StringBuilder</code> )</li> </ul> <p><strong><code>equals(Object anObject)</code>:</strong></p> <ul> <li>Lets you check equality of given string value with any instance of type <code>java.lang.String</code> <strong>only</strong></li> </ul> <p><strong>RTFC :)</strong></p> <p>Since reading the source is the best way to understand it, I am sharing the implementations of both the methods (as of jdk 1.7.0_45)</p> <pre><code>public boolean contentEquals(CharSequence cs) { if (value.length != cs.length()) return false; // Argument is a StringBuffer, StringBuilder if (cs instanceof AbstractStringBuilder) { char v1[] = value; char v2[] = ((AbstractStringBuilder) cs).getValue(); int i = 0; int n = value.length; while (n-- != 0) { if (v1[i] != v2[i]) return false; i++; } return true; } // Argument is a String if (cs.equals(this)) return true; // Argument is a generic CharSequence char v1[] = value; int i = 0; int n = value.length; while (n-- != 0) { if (v1[i] != cs.charAt(i)) return false; i++; } return true; } </code></pre> <hr> <pre><code>public boolean equals(Object anObject) { if (this == anObject) { return true; } if (anObject instanceof String) { String anotherString = (String) anObject; int n = value.length; if (n == anotherString.value.length) { char v1[] = value; char v2[] = anotherString.value; int i = 0; while (n-- != 0) { if (v1[i] != v2[i]) return false; i++; } return true; } } return false; } </code></pre> <hr> <p>There is another method of String#contentEquals():</p> <pre><code>public boolean contentEquals(StringBuffer sb) { synchronized(sb) { return contentEquals((CharSequence)sb); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload