Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Set; 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 Comparator<String> mComparator = new Comparator<String>() { @Override public int compare(String a, String b) { return Integer.valueOf(a) - Integer.valueOf(b); } }; public static boolean isLowestLevel(int level) { if (mLevelSet == null) mLevelSet = mContext.getSharedPreferences(PREFER, Context.MODE_WORLD_READABLE).getStringSet(LEVELSET, null); if (mLevelSet != null) { if (mLevelSet.size() < 5) // data is too few to judge lowest return false; ArrayList<String> array = Collections.list(Collections.enumeration(mLevelSet)); Collections.sort(array, mComparator); // TODO: may need check statistics to ensure the level is true lowest and not false alarm. if (level <= Integer.valueOf(array.get(0))) return true; } return false; } }