0

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?

1
  • Try this, Images.MyListArrayList.clear(); Images.MyListArrayList.addAll(Arrays.asList(s.split(","))); Commented Mar 21, 2016 at 12:29

1 Answer 1

3
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]);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.