---
title: "Iterating Through a Sparse Array"  
description: "Iterating Through a Sparse Array"  
author: "Anonymous User"  
published: 2014-10-10  
updated: 2014-10-10  
canonical: https://www.mindstick.com/forum/2361/iterating-through-a-sparse-array  
category: ".net"  
tags: ["c#", ".net"]  
reading_time: 1 minute  

---

# Iterating Through a Sparse Array

Is there a way to iterate over [java](https://www.mindstick.com/articles/12214/web-development-company-in-india-laid-on-the-foundation-of-concrete-java-programming) SparseArray (for [android](https://www.mindstick.com/articles/13046/10-reasons-why-i-prefer-android-vs-iphone-ios)) ? I used sparsearray to easily get [values](https://www.mindstick.com/forum/327/sum-textbox-values) by index.

I could not find one.

## Replies

### Reply by Anonymous User

seems I found the solution. I haven't properly noticed keyAt(index) function.\
So I'll go with something like this

```
int key = 0;        for (int i = 0; i < sparseArray.size(); i++)        {            key = sparseArray.keyAt(i);            // get the object by the key.            Object obj = sparseArray.get(key);        }
```


---

Original Source: https://www.mindstick.com/forum/2361/iterating-through-a-sparse-array

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
