I am getting a list from the json response that I want to convert to strings.
String fruits = remoteMessage.getData().get("fruits");
The above line gives me the following response,
["California Apple","Mango","Mexico Original Banana"]
Now, what I need is,
"California Apple", "Mango", "Mexico Original Banana"
How could this be achieved?
CodePudding user response:
With the Arrays.asList () utility method you can do what you want. Note only works with primitive data types.
List<String> list = Arrays.asList(fruits);
;)
CodePudding user response:
Delete First and Last character using StringBuffer
String fruits = remoteMessage.getData().get("fruits");
StringBuffer sb=new StringBuffer(fruits);
sb.deleteCharAt(0);
sb.deleteCharAt(sb.length()-1);
fruits = sb.toString();
Output
"California Apple", "Mango", "Mexico Original Banana"