使用commit()方法或apply()方法来提交SharedPreferences的更改,并使用putStringSet()方法来保存ArrayList中的数据。下面是示例代码:
// 创建一个存储ArrayList的SharedPreferences SharedPreferences sharedPref = getSharedPreferences("myPrefs", Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPref.edit();
// 将ArrayList转换为Set并存储到SharedPreferences中
Set
// 提交更改 editor.apply(); // 或者使用editor.commit();