共享首选项 - HashSet <string> / Set <string> limit / max size

时间:2015-11-18 14:53:07

标签: android sharedpreferences hashset

我正在使用SharedPreferences来存储Set个字符串,使用.putStringSet(),但我无法使用.getStringSet()从中获取超过99个项目。

  • HashSet<String>/Set<String>是否有尺寸限制?
  • 如果是,我该如何增加/改变它?

请参阅以下代码:

//Always return 99 items.
private Set<String> getIdentifers(){
    Set<String> identifiers = preferences.getStringSet("my_ids", new HashSet<String>());
    return new HashSet<String>(identifiers);
}

//`Identifiers` contains 100 items.
private Boolean saveIdentifier(Set<String> identifiers){
    SharedPreferences.Editor editor = preferences.edit();
    editor.putStringSet("my_ids", identifiers);
    return editor.commit(); 
}

//`Identifiers` show 100 items on Android Studio Debug Console after added `Identifier`to it.
public Boolean addIdentifierToMemory(String identifier){
    Set<String>identifiers = getIdentifers(); //99 items
    identifiers.add(identifier); //99 items
    return savePurchasedProductsIdentifier(identifiers); //100 items
}

0 个答案:

没有答案