So I was looking up how to change a String
set to an ArrayList<sSring>
and I couldn't find anything. I tried:
favorites = new ArrayList( mPrefsaved.getStringSet("faves", null) ;
How can I convert a StringSet
into an ArrayList<string>
?
I tried:
private void getsaved() {
favorites = new ArrayList<String>(mPrefsaved.getStringSet("faves", null));
}
But log Cat told me NullPointerException
Consider you have a set of Strings like
Set<String> set = new HashSet<String>();
// some elements in set
then you can try
List<String> listFromSet = new ArrayList<String>(yourCurrentSet);
in your case .
List<String> listFromSet = new ArrayList<String>(mPrefsaved.getStringSet("faves", null));
Make sure that your method getStringSet
returns a collection of Strings.
Use foreach in stringset and add each string to arraylist
ArrayList<String> arrayList = new ArrayList<String>();
for (String str : stringset)
arrayList.add(str);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With