我有一个字符串
String str = "Hello there how are you"
和一个子字符串
String substr = "how are you".
我正在检查字符串是否包含这样的子字符串:
if (str.toLowerCase().contains(substr.toLowerCase())) {
// now check if substr is the last part of str
}
如果子字符串在字符串中,我想检查该子字符串是否是字符串的最后部分。无论如何我可以做到这一点吗?谢谢!
最佳答案
您会想要 String.endsWith()
方法:
if (str.toLowerCase().endsWith(substr.toLowerCase())
关于java - 如何检查子字符串是否位于字符串末尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27828426/