問一個神奇的問題:
<c:out value="${fn:endsWith('helle','e') }"></c:out>
<c:out value="${fn:endsWith('hhlle','e') }"></c:out>
訪問的時候顯示 false true 。 為什么啊??????
<c:out value="${fn:endsWith('helle','e') }"></c:out>
<c:out value="${fn:endsWith('hhlle','e') }"></c:out>
訪問的時候顯示 false true 。 為什么啊??????
2016-10-04
舉報
2016-10-05
public static boolean endsWith(String input, String substring) {
? ?if(input == null) {
? ? ? ?input = "";
? ?}
? ?if(substring == null) {
? ? ? ?substring = "";
? ?}
? ?int index = input.indexOf(substring);
? ?return index == -1?false:(index == 0 && substring.length() == 0?true:index == input.length() - substring.length());
}
這是它的源碼,你看了這個應(yīng)該就明白了,
最后index == input.length() - substring.length(),在helle中,input.length()為5,而substring.length()為1,
而index為1,所以index!=5-1,所以返回false