场景:工作需要动态保存一个map,每次需要进行查询是否有某个元素,有的话就不保存,没有就保存
保存map
/**
* 用于保存集合
*
* @param map map数据
* @return 保存结果
*/
public static <K, V> boolean putHashMapData(Map<K, V> map) {
boolean result;
SharedPreferences sp = MyApplication.getContext().getSharedPreferences("SIGN", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
try {
Gson gson = new Gson();
String json = gson.toJson(map);