Back to Blog
Kotlin loop through list5/28/2023 ![]() ![]() So, internally, you loop through 65 to 90 to print the English alphabets. In this guide, we will learn how to use for loop. This is a simple solution for the underlying problem of your first code: A ConcurrentModificationException is thrown because you iterate through the list and removing from it at the same time.Įasy solution is to create a copy of the list and iterate through that. Like Java, you can loop through A to Z using a for loop because they are stored as ASCII characters in Kotlin. The for loop in Kotlin is used to iterate or cycle though the elements of array, ranges, collections etc. Let's look at the alternatives: Iterating over a copy, removing from original In Kotlin, for loop is used to iterate through the following because all of them provides iterator.
0 Comments
Read More
Leave a Reply. |