0

我需要制作一个 ArrayList 列表,我的想法是:

 Map<Integer, ArrayList<String>> SentReportMap=new HashMap<Integer, ArrayList<String>>();

那告诉:

 Use new SparseArray<ArrayList<String>>(...) instead for better performance

所以,我试试这个:

 SparseArray<String> SentReportMap = new SparseArray<String>();

 ArrayList<String> items=new ArrayList<String>();

 items.add(array.getProperty("To").toString());
 items.add(array.getProperty("Date").toString());

 SentReportMap.put(1, items);

但是用数据填充这个数组,返回这个错误:

The method put(int, String) in the type SparseArray<String> is not applicable for the arguments (int, ArrayList<String>)

或者

The method put(int, String) in the type SparseArray<String> is not applicable for the arguments (ArrayList<String>, int)

哪里错了,什么是制作数组数组的更好解决方案!?

4

2 回答 2

0

改变

 SparseArray<String> SentReportMap = new SparseArray<String>();

SparseArray<ArrayList<String>> SentReportMap = new SparseArray<ArrayList<String>>();

SparseArray 是更好的解决方案,因为:

SparseArrays map integers to Objects. Unlike a normal array of Objects, there can be gaps in the indices. It is intended to be more memory efficient than using a HashMap to map Integers to Objects, both because it avoids auto-boxing keys and its data structure doesn't rely on an extra entry object for each mapping.

检查此链接以获取更多信息。

http://developer.android.com/reference/android/util/SparseArray.html

于 2014-08-16T09:33:33.063 回答
0

SentReportMap 的声明是错误的,应该是:

SparseArray<ArrayList<String>> SentReportMap = new SparseArray<ArrayList<String>>();
于 2014-08-16T09:35:07.643 回答