Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Accessing array that is in Map

what i want to achieve is check if data in map is an array and if yes get the first value from the array

Here you can see I have couple of arrays in Map and I want to access them and get the first value.

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What I did so far is just loop through the map so I can print it.

  val map : MutableMap<String, Any>? = document.data?.toSortedMap(compareBy<String> { it.length }.thenBy { it })

  map?.forEach {
       Log.d("test", it.toString())
  }

>Solution :

Not sure what is your end goal but this should do the trick

  map?.forEach { (key, value) ->
       if(value is Array<*>){
          //value.get(0) //mby also should add check if array is not empty before getting the value
       }
       Log.d("test", it.toString())
  }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading