Wednesday, February 25, 2015

Searching last occurance in a java pgm



Searching last occurance

public class SearchlastString
{
   public static void main(String[] args)
   {
      String strOrig = "Hello world ,Hello Reader";
      int lastIndex = strOrig.lastIndexOf("Hello");
      if(lastIndex == - 1)
      {
         System.out.println("Hello not found");
      }
        else
        {
         System.out.println("Last occurrence of Hello
         is at index "+ lastIndex);
      }
   }
}
 


No comments:

Post a Comment