我需要做一个数组列表,我的想法是:
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)
哪里是错误的,什么是更好的解决方案,使数组的数组列表!?
SentReportMap的声明是错误的,它应该是:
SparseArray<ArrayList<String>> SentReportMap = new SparseArray<ArrayList<String>>();
change
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