Reputation: 12743
The input is XYZ
The String array contains three string i.e.
I need the last two result if i provide the input "XYZ". Not the test.alpha.beta.XYZWorld. if i use lastIndexOf method defined in java.lang.String, obviously it returns 1,2 and 3 result.
Please help.
Upvotes: 2
Views: 584
Reputation: 46408
check out String.endsWith(suffix) method from String API. it returns a boolean value.
String s = "test.gamaa.mu.XYZ";
System.out.println(s.endsWith("XYZ"));
returns TRUE
Upvotes: 2
Reputation: 1902
String pattern = "xyz";
String a = "xyz";
String b = "xyzA";
int position = b.lastIndexOf(pattern);
if (b.length() == position + pattern.length())
{
System.out.print("OK");
} else
{
//error
}
Upvotes: 2