Can anyone explain to me how to modify this to wor...
# announcements
s
Can anyone explain to me how to modify this to work in kotlin? There is no
hasNext()
method
, so I cannot perform whether there is an end in the
while
.
Copy code
public static void printEachForward(BreakIterator boundary, String source) {
     int start = boundary.first();
     for (int end = boundary.next();
          end != BreakIterator.DONE;
          start = end, end = boundary.next()) {
          System.out.println(source.substring(start,end));
     }
 }
✔️ 1
b
Copy code
fun printEachForward(boundary: BreakIterator, source: String) {
    var start = boundary.first()
    var end = boundary.next()
    while (end != BreakIterator.DONE) {
        println(source.substring(start, end))
        start = end
        end = boundary.next()
    }
}
s
fantastic. Thanks. Having a bit of trouble this morning.