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 に答える