1

I want to map array from Firebase as a list of string in Kotlin

enter image description here

I have been searching for answer in may threads but they doesn't answer my question

Now I fetch whole collection and I get DocumentSnapshot. When I do

  list = it["myArray"].toString()

I get string:

list = [text1, text2, text3]

How Can I convert it to list?

1 Answer 1

1

You can use split() like,

val newList = list.split(',')

It will split the strings from every occurrence of ',' in it, and will return a list containing all the spliced strings.

Sign up to request clarification or add additional context in comments.

1 Comment

Don't forget to remove brackets and whitespaces. fun String.removeBrackets(): String { return this .replace("[", "") .replace("]", "") .trim() }

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.