Java tutorial
//package com.java2s; import java.util.Set; import java.util.TreeSet; import android.content.Context; public class Main { private static Context mContext; private static String PREFER = "LuxLevel"; private static String LEVELSET = "levelSet"; private static Set<String> mLevelSet = null; private static boolean levelExist(int level) { if (mLevelSet == null) mLevelSet = mContext.getSharedPreferences(PREFER, Context.MODE_WORLD_READABLE).getStringSet(LEVELSET, null); if (mLevelSet == null) { mLevelSet = new TreeSet<String>(); mLevelSet.add(String.valueOf(level)); mContext.getSharedPreferences(PREFER, Context.MODE_WORLD_WRITEABLE).edit() .putStringSet(LEVELSET, mLevelSet).commit(); return false; } if (mLevelSet.contains(String.valueOf(level))) return true; else { mLevelSet.add(String.valueOf(level)); mContext.getSharedPreferences(PREFER, Context.MODE_WORLD_WRITEABLE).edit() .putStringSet(LEVELSET, mLevelSet).commit(); } return false; } }