Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/369.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.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
如何在Java或Android中拆分集合_Java_Android_Arrays_Hashset - Fatal编程技术网

如何在Java或Android中拆分集合

如何在Java或Android中拆分集合,java,android,arrays,hashset,Java,Android,Arrays,Hashset,在上面的代码中,我希望通过split方法或根据大小的任何其他方法获得每个字符串。因为所有的值都在集合中。我无法像对数组使用拆分方法那样获得每个值。那么,有谁能帮我一下吗。将集合转换为字符串[],然后您可以像这样循环所有条目: private SharedPreferences sharedpre = null; private SharedPreferences.Editor saveuser = null; Set<String> pathNamesImage = new Has

在上面的代码中,我希望通过split方法或根据大小的任何其他方法获得每个字符串。因为所有的值都在集合中。我无法像对数组使用拆分方法那样获得每个值。那么,有谁能帮我一下吗。

将集合转换为字符串[],然后您可以像这样循环所有条目:

private SharedPreferences sharedpre = null;
private SharedPreferences.Editor saveuser = null;

Set<String> pathNamesImage = new HashSet<String>();
saveuser = sharedpre.edit();

pathNamesImage.add(pathLocal);
saveuser.putStringSet("prePathNames", pathNamesImage);
注意:我看到您正在使用SharedReferences和StringSet。。。在SharedReferences中修改StringSet时,请注意这个棘手的问题:

请注意,您不能修改此调用返回的set实例。 如果您这样做,则无法保证存储数据的一致性,也无法保证 您修改实例的能力


为什么要使用Set并执行拆分,为什么不使用array/List,以便在将元素放入时检查重复?@almasshaikh因为我使用共享首选项在另一个活动中保存和检索值,并在android中拆分它
Set<String> pathNamesImage = new HashSet<String>();

// Initialize a string array to hold all your set entries
String[] stringArray= new String[pathNamesImage.size()];

// Now, you can iterate over Set, by using the array
for(String str : pathNamesImage.toArray(stringArray)){
    Log.d("yeah", "str:" + str);        
}