Java tutorial
//package com.java2s; // Licensed under the MIT license. import android.content.Context; import android.content.SharedPreferences; import java.util.HashSet; import java.util.List; import java.util.Set; public class Main { public static void deletePersonGroups(List<String> personGroupIdsToDelete, Context context) { SharedPreferences personGroupIdNameMap = context.getSharedPreferences("PersonGroupIdNameMap", Context.MODE_PRIVATE); SharedPreferences.Editor personGroupIdNameMapEditor = personGroupIdNameMap.edit(); for (String personGroupId : personGroupIdsToDelete) { personGroupIdNameMapEditor.remove(personGroupId); } personGroupIdNameMapEditor.commit(); Set<String> personGroupIds = getAllPersonGroupIds(context); Set<String> newPersonGroupIds = new HashSet<>(); for (String personGroupId : personGroupIds) { if (!personGroupIdsToDelete.contains(personGroupId)) { newPersonGroupIds.add(personGroupId); } } SharedPreferences personGroupIdSet = context.getSharedPreferences("PersonGroupIdSet", Context.MODE_PRIVATE); SharedPreferences.Editor personGroupIdSetEditor = personGroupIdSet.edit(); personGroupIdSetEditor.putStringSet("PersonGroupIdSet", newPersonGroupIds); personGroupIdSetEditor.commit(); } public static Set<String> getAllPersonGroupIds(Context context) { SharedPreferences personGroupIdSet = context.getSharedPreferences("PersonGroupIdSet", Context.MODE_PRIVATE); return personGroupIdSet.getStringSet("PersonGroupIdSet", new HashSet<String>()); } }