当前位置:网站首页>Clear function of ArrayList

Clear function of ArrayList

2022-06-11 05:42:00 wy36228

There is a problem with the following code ,list_RowData.clear() After calling ,list_Data The stored data in is also cleared .

List<ArrayList> list_Data = new ArrayList<ArrayList>();
ArrayList list_RowData = new ArrayList<>();
if(cursor_selectedTable.moveToFirst())
{
do{
for (int i = 2; i<cursor_selectedTable.getColumnCount();i++)
{
list_RowData.add(cursor_selectedTable.getString(i));
}
list_Data.add(list_RowData);
list_RowData.clear();
}while (cursor_selectedTable.moveToNext());
}

This explanation list_Data.add(list_RowData); Just quoted list_RowData The address of , Change it to :

list_Data.add(new ArrayList(list_RowData));

Can solve the problem .

原网站

版权声明
本文为[wy36228]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203020536399766.html