Convert SparseBooleanArray as Integer List - Android android.util

Android examples for android.util:SparseArray

Description

Convert SparseBooleanArray as Integer List

Demo Code


//package com.java2s;
import android.util.SparseBooleanArray;
import java.util.ArrayList;

public class Main {
    public static ArrayList<Integer> asKeyList(
            SparseBooleanArray sparseArray) {
        ArrayList<Integer> arrayList = null;
        if (sparseArray != null && sparseArray.size() > 0) {
            int count = sparseArray.size();
            arrayList = new ArrayList<>(count);
            for (int i = 0; i < count; i++) {
                arrayList.add(sparseArray.keyAt(i));
            }/*from   w w  w . j av  a2s.  c o m*/
        }
        return arrayList;
    }
}

Related Tutorials