请问下题的结果是多少?
System.out.println("this is a Sample.".lastIndexOf("i"));
主要是想问一下,lastIndexOf()的用法。

解决方案 »

  1.   

    "返回指定字符在此字符串中最后一次出现处的索引"
    字符i在“This is a Sample”中最后出现处应是this中的i。
      

  2.   

    0t
    1h
    2i
    3s
    4
    5i
      

  3.   

    从左到右,最后出现的i在is里。
      

  4.   

    <script type="text/javascript">var str="Hello world!"
    document.write(str.lastIndexOf("Hello") + "<br />")
    document.write(str.lastIndexOf("World") + "<br />")
    document.write(str.lastIndexOf("world"))</script>
    以上代码的输出:
    0
    -1
    6