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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
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: 18765
    
  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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: doubt in program of String Handling- please review