Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 共享首选项多字符串集问题_Android_Android Sharedpreferences - Fatal编程技术网

Android 共享首选项多字符串集问题

Android 共享首选项多字符串集问题,android,android-sharedpreferences,Android,Android Sharedpreferences,我正在尝试将原始字符串集复制到其他三个字符串集。如下图所示存储/复制后,如果我尝试打印内容,则内容不同。谢谢你的帮助 { SharedPreferences sp = this.getSharedPreferences("SS", 0); Set<String> s = new HashSet<String>(sp.getStringSet("DD", new HashSet<String>())); Object[

我正在尝试将原始字符串集复制到其他三个字符串集。如下图所示存储/复制后,如果我尝试打印内容,则内容不同。谢谢你的帮助

{       
    SharedPreferences sp = this.getSharedPreferences("SS", 0);
    Set<String> s = new HashSet<String>(sp.getStringSet("DD", new HashSet<String>()));  

    Object[] array = s.toArray();

    SharedPreferences.Editor editor = sp.edit();
    editor.putStringSet("CC", s);                   
    editor.commit();

    Set<String> zz = new HashSet<String>(sp.getStringSet("ZZ", new HashSet<String>())); 
    zz.add(array[0].toString());
    zz.add(array[1].toString());

    SharedPreferences.Editor editor_zz = sp.edit();
    editor_zz.putStringSet("ZZ", ZZ);                   
    editor_zz.commit();

    Set<String> hop = new HashSet<String>(sp.getStringSet("HH", new HashSet<String>()));    
    hop.add(array[1].toString());
    hop.add(array[0].toString());

    SharedPreferences.Editor editor_hop = sp.edit();
    editor_hop.putStringSet("HH", hop);                 
    editor_hop.commit();


    logSet = null;
    iterator = null;

    logSet = new HashSet<String>(sp.getStringSet("ZZ", new HashSet<String>()));
    iterator = logSet.iterator();
    while (iterator.hasNext())
    {
        String zz = iterator.next();
        Log.d("wrong string Y??","ZZList "+zz);
    }


}
{
SharedReferences sp=this.getSharedReferences(“SS”,0);
Set s=newhashset(sp.getStringSet(“DD”,newhashset());
对象[]数组=s.toArray();
SharedReferences.Editor=sp.edit();
编辑器.putStringSet(“CC”,s);
commit();
Set zz=新的HashSet(sp.getStringSet(“zz”,new HashSet());
add(数组[0].toString());
add(数组[1].toString());
SharedReferences.Editor_zz=sp.edit();
编辑_zz.putStringSet(“zz”,zz);
编辑器_zz.commit();
Set-hop=newhashset(sp.getStringSet(“HH”,newhashset());
添加(数组[1].toString());
添加(数组[0].toString());
SharedReferences.Editor\u-hop=sp.edit();
编辑器_hop.putStringSet(“HH”,hop);
编辑器_-hop.commit();
logSet=null;
迭代器=null;
logSet=newhashset(sp.getStringSet(“ZZ”,newhashset());
迭代器=logSet.iterator();
while(iterator.hasNext())
{
字符串zz=iterator.next();
Log.d(“错误的字符串Y??”、“ZLIST”+zz);
}
}

副本与原始副本有何不同?字符串值的顺序不同,字符串集的名称也不同,它们将通过各自的字符串集访问。这样做有问题吗?你不应该依赖于字符串的顺序。由于这是一个集合,因此不能保证保留顺序,副本与原始副本有何不同?字符串值的顺序不同,字符串集合的名称也不同,它们将使用各自的字符串集合进行访问。这样做有问题吗?你不应该依赖于字符串的顺序。由于这是一个集合,因此不能保证保留顺序,