class Test { void f(String value) { final int index = -1; while ((index = value.indexOf('a')) != -1) { value = value.substring(0, 1); } } }