Convert SparseArrayCompat as List - Android android.util

Android examples for android.util:SparseArray

Description

Convert SparseArrayCompat as List

Demo Code


//package com.java2s;
import android.support.v4.util.SparseArrayCompat;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static <T> List<T> asList(SparseArrayCompat<T> sparseArray) {
        if (sparseArray == null) {
            return null;
        }// w w  w.  j a v a  2 s.c o m

        List<T> list = new ArrayList<>(sparseArray.size());
        for (int i = 0; i < sparseArray.size(); i++) {
            list.add(sparseArray.valueAt(i));
        }
        return list;
    }
}

Related Tutorials