0

i need to make a List of ArrayList , my idea was it:

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

that tell :

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

so , i try this :

 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);

but for fill this array with data , return this error :

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

Or

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

where is wrong and what is better solution for making a arraylist of arrays!?

Krypton
  • 3,337
  • 5
  • 32
  • 52
Saeid
  • 2,261
  • 4
  • 27
  • 59

2 Answers2

0

change

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

to

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

SparseArray is better solution because :

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.

check this link for more information.

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

mmlooloo
  • 18,937
  • 5
  • 45
  • 64
0

Declaration of SentReportMap is wrong, it should be:

SparseArray<ArrayList<String>> SentReportMap = new SparseArray<ArrayList<String>>();
Krypton
  • 3,337
  • 5
  • 32
  • 52