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 String dumpLuxLevel() { String result = ""; if (mLevelSet == null) mLevelSet = mContext.getSharedPreferences(PREFER, Context.MODE_WORLD_READABLE).getStringSet(LEVELSET, null); if (mLevelSet != null) { ArrayList<String> array = Collections.list(Collections.enumeration(mLevelSet)); Collections.sort(array, mComparator); result = array.toString(); } return result; } }