更新时间:2023-02-02 21:31:45
考虑 bigInts
是的BigInteger []
你想从 preference
:
的BigInteger [] bigInts =新的BigInteger [N];
设置<字符串>设置=新的HashSet<字符串>();
对于(BigInteger的BIGINT:bigInts){
set.add(bigInt.toString());
}
//存入preference
共享preference.Editor编辑= getShared preference(getPackageName(),Context.MODE_PRIVATE).edit();
editor.putStringSet(bigints,设置);
//获取BitInteger []由preference
共享preference preF = getShared preference(getPackageName(),Context.MODE_PRIVATE);
设置<字符串>设置= pref.getStringSet(bigints,新的HashSet<字符串>());
诠释计数= set.size();
的String [] =可疑交易报告新的String [统计]
BigInteger的[] bigInts =新的BigInteger [统计]
set.toArray序列(STR);
的for(int i = 0; I<计数;我++){
bitInts [我] =新的BigInteger序列(STR [I]);
}
I want to save/load a BigInteger
array into/from the SharedPreferences.
How can it be done?
For example for the following array:
private BigInteger[] dataCreatedTimes = new BigInteger[20];
Consider bigInts
is the BigInteger[]
you want from Preference
:
BigInteger[] bigInts = new BigInteger[n];
Set<String> set = new HashSet<String>();
for(BigInteger bigInt : bigInts) {
set.add(bigInt.toString());
}
//store into Preference
SharedPreference.Editor editor = getSharedPreference(getPackageName(), Context.MODE_PRIVATE).edit();
editor.putStringSet("bigints", set);
//get BitInteger[] from Preference
SharedPreference pref = getSharedPreference(getPackageName(), Context.MODE_PRIVATE);
Set<String> set = pref.getStringSet("bigints", new HashSet<String>());
int count = set.size();
String[] strs = new String[count];
BigInteger[] bigInts= new BigInteger[count];
set.toArray(strs);
for(int i = 0; i < count; i++) {
bitInts[i] = new BigInteger(strs[i]);
}