class kki{
 public static void main(String arg[]){
  String banner="onemanonevote";
  int subind1=banner.lastIndexOf("one",4);
  System.out.println(subind1);
 }
}
结果是0
public int lastIndexOf(String str,
                       int fromIndex)
从指定的索引处开始向后搜索,返回在此字符串中最后一次出现的指定子字符串的索引。返回的整数是最大值 k,它满足: 
     k <= Math.min(fromIndex, str.length()) && this.startsWith(str, k)
好像不对呢 , 根据这个答案应该是6, 解释一下.

解决方案 »

  1.   

    fromIndex=4,str.length()=13,所以k<=4public int lastIndexOf(String str,
                           int fromIndex)
    返回指定子字符串在此字符串中最后一次出现处的索引,从指定的索引开始反向搜索。返回的整数是满足下式的最大 k 值: 
         k <= Math.min(fromIndex,this.length()) && this.startsWith(str, k)
     如果不存在这样的 k 值,则返回 -1。 
    这是API帮助上的,奇怪怎么和你的意思好像相反
      

  2.   

    Returns the index within this string of the last occurrence of the
    specified substring, searching backward starting at the specified index.
    The integer returned is the largest value注意这儿的searching backward!!!!!!
      

  3.   

    oneamnonev o t  e
    0123456789 10 11 12banner.lastIndexOf("one",4);
    上边的意思我的理解是从banner字符串的下标第四位开始查找"one".也就是从"nonevote"开始查找.那n的下标正好是0.所以返回值是0.说的不对请指正
      

  4.   

    是不是和fromIndex的值的大小有关系
    我去试了下
    从0-5
    结果都是0
    0-5<6的从6和6以后
    结果都是6返回的整数是最大值 k,它满足: 
         k <= Math.min(fromIndex, str.length()) && this.startsWith(str, k)
    不知道这句是不是我上面那种理解
      

  5.   

    就是说返回的值不会大于fromIndex
    感觉有点怪怪的
      

  6.   

    “Returns the index within this string of the last occurrence of the
    specified substring, searching backward starting at the specified index.
    The integer returned is the largest value注意这儿的searching backward!!!!!!”
    看来还是这位《flyforlove(吾将远去)》说得对
    字符串是form开始从后向前搜索子串从
    “是不是和fromIndex的值的大小有关系
    我去试了下
    从0-5
    结果都是0
    0-5<6的从6和6以后
    结果都是6返回的整数是最大值 k,它满足: 
         k <= Math.min(fromIndex, str.length()) && this.startsWith(str, k)
    不知道这句是不是我上面那种理解”这些现象就可以看出来了!
    大家理解了吗?
      

  7.   

    banner.lastIndexOf("one",4);晕这个不难解释啊...lastIndexOf(搜索的字段,搜索起始位)你从第4个开始..从后往前..当然是0位