如何保存/载入BigInteger的数组 [英] How to save/load BigInteger array

查看:360
本文介绍了如何保存/载入BigInteger的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想保存/载入的BigInteger 数组/从共享preferences。 怎样才能做到呢?

例如对于下面的数组:

 私人的BigInteger [] dataCreatedTimes =新的BigInteger [20];
 

解决方案

考虑 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]);
}

这篇关于如何保存/载入BigInteger的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆