Reputation: 748
We have an Array List consisting of many strings.
public final static ArrayList<String> MyListArrayList= new ArrayList<String>(){{}};
And we converted the array list into a comma separated string using below code
gson = new Gson();
listOfTestObject = new TypeToken<ArrayList<String>>(){}.getType();
MyListString = gson.toJson(Images.MyListArrayList, listOfTestObject);
Now we have a comma separated string like
"Item1,Item2,Item3,Item3.....Itemn"
and we are saving this string using the preference whenever the array list gets updated. So now we need to load this string at starting and then convert the string back into the array List.For that we are trying below code
List<String> Images.MyListArrayList= new ArrayList<String>(Arrays.asList(s.split(",")));
But its not possible to do it.But we can create a new List.. But we want to update the already existing Array List instead of creating new one. How to do it?
Upvotes: 0
Views: 747
Reputation: 939
String value="Item1,Item2,Item3,Item3.....Itemn";
String[] arrayList = value.split(",");
ArrayList list = new ArrayList<String>();
for (int i = 0; i < arrayList.length; i++) {
list .add(arrayList[i]);
}
Upvotes: 3