Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (4k points)
Is there a way to iterate over Java SparseArray (for Android) ? I used sparsearray to easily get values by index. I could not find one.

1 Answer

0 votes
by (46k points)

Here's the solution you need. I hadn't accurately discerned the keyAt(index) function.

So I'll try with something like this:

for(int i = 0; i < sparseArray.size(); i++) {

   int key = sparseArray.keyAt(i);

   // get the object by the key.

   Object obj = sparseArray.get(key);

}

Related questions

0 votes
1 answer
asked Nov 12, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer
0 votes
1 answer
asked Jul 27, 2019 in Java by Ritik (3.5k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...