| 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: 16687
|
|
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
|
|
|