如何在字符串
中从后到前查找.
String calc = "abcd+abcd.abcd+abcd-abcd.abcd"
for (int i = calc.length(); i > 0; i--) {
if (calc.charAt(i) == '.') {
//Do something
}
}
答案 0 :(得分:3)
几乎正确,我相信你想要 -
// for (int i = calc.length(); i > 0; i--) {
for (int i = calc.length() - 1; i >= 0; i--) { // <-- 0 is the first character.