0

I want to iterate through my ArrayList named parts, here is my code:

for(x in parts.indices){
            Log.i("INFO", parts.indices.toString())
        }

The output is the following:

0..52
0..52

But I'd expect 0..52 to be printed 53 times. I've tried changing x in parts.indices to x in 0 until parts.size, but the output remains the same. Interestingly enough, when I use the same construction in another class with the same imports it works ok. What am I doing wrong?

5
  • 0..52 .... looping 53 times..0,1,2...52 Commented Jun 1, 2018 at 11:43
  • 3
    Your problem is not reproducible. It's probably on the level of log output, not program logic. (0..52).toList().also { parts -> for (x in parts.indices) println(parts.indices) } -- prints 0..52 53 times. Commented Jun 1, 2018 at 12:01
  • What's the reason for iterating over indices instead of using parts.forEach()? Commented Jun 1, 2018 at 14:25
  • @Pawel I just need the indices to perform some calculations later on Commented Jun 1, 2018 at 15:42
  • 1
    @A.W. Use parts.map { indices } then. Commented Jun 1, 2018 at 15:49

1 Answer 1

1

It is a Log issue, as noted by @Marko Topolnik, it seems to be 'folding' the output when strings are identical. Println does it as well, but at least prints a message saying 'identical 51 lines'.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.