An IDE warning
No. 211
|
Q: |
We consider: 01 /**
02 * <p>Check a string for ending with a particular character.</p>
03 *
04 * <p>Example: <code>"Environment"</code> ends with character <code>'t'</code>.</p>
05 *
06 * @param s The string to be inspected.
07 * @param c The char to be searched for.
08 * @return true if s ends with character c, false otherwise
09 */
10
11 static boolean endsWith (final String s, final char c) {
12 return s.indexOf(c) == s.length();
13 }The IDE issues a warning corresponding to line 12: Condition 's.indexOf(c) == s.length()' is always 'false' Explain the underlying flaw and provide a fix.
TipYou may want to consult the |
|
A: |
The
|
