We would like to know how to search the last occurrence of 'a' in the String.
public class MainClass{ // w w w .j a v a 2 s . co m public static void main(String[] arg){ String str = "abcdea"; int index = 0; index = str.lastIndexOf('a'); System.out.println(index); } }
The code above generates the following result.