The input is XYZ
The String array contains three string ie
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.
String
有一个endsWith()
方法。
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
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
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.