File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes doubt in program of String Handling- please review Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "doubt in program of String Handling- please review" Watch "doubt in program of String Handling- please review" New topic
Author

doubt in program of String Handling- please review

vijay kumar dahiya
Ranch Hand

Joined: Oct 19, 2008
Posts: 33
public static void main(String[] args) {
String s="vijay kumar";
System.out.println(s);
System.out.println(s.lastIndexOf('k');
System.out.println(s.lastIndexOf('k',4));
System.out.println(s.lastIndexOf('k',9));
}

ouput is:
s.lastIndexOf('k') is: 6
s.lastIndexOf('k',4) is: -1
s.lastIndexOf('k',9) is: 6

please write me how it print is:
s.lastIndexOf('k',4) is: -1
s.lastIndexOf('k',9) is: 6

thanks.

Vijay
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18554
    
  40

s.lastIndexOf('k',4) is: -1


If you start at index position 4, and search backwards for the 'k', where would you find it? Or will you find it?

s.lastIndexOf('k',9) is: 6


If you start at index position 9, and search backwards for the 'k', where would you find it?

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
vijay kumar dahiya
Ranch Hand

Joined: Oct 19, 2008
Posts: 33
thanks you Mr. Henry.
 
 
subject: doubt in program of String Handling- please review
 
Similar Threads
Getting the Last token from a String
Mughal String.lastIndexOf
Doubt with String.lastIndexOf ( Recreated topic from k.pandu)
lastIndexOf(int ch, int fromIndex) in Strings
Problem related to enums