How to call the veritable out of the function

Hello everyone, I am new to Kotlin and I am working on my first app, but I have a difficulty about calling a function.
How to call the veritable out of the function that I define in the function?
Thank you so much for your help.

The codes are below:

private fun parseItems(jsonResponse: String) {

    val list = ArrayList<HashMap<String, String>>()

    try {
        val jobj = JSONObject(jsonResponse)
        val jarray = jobj.getJSONArray("items")
        val corrAns = Array(jarray.length()) { i -> " $i"  }

        for (i in 0 until jarray.length()) {
            val jo = jarray.getJSONObject(i)
            val queNo = jo.getString("queNo")
            val queContent = jo.getString("queContent")
            corrAns[i]  = queContent
         

            val item = HashMap<String, String>()
            item["queContent"] = queContent
            list.add(item)
            println("This is corrAns ${corrAns[i]}.")
        }

    } catch (e: JSONException) {
        e.printStackTrace()
    }
}
...
println(arrayOf("corrAns"))

Msg from logcat:
2019-09-24 22:41:38.316 18913-18913/com.example.input_que_db I/System.out: [Ljava.lang.String;@576dfb0

Do you mean that you want to access corrAns outside of function parseItems?

Yes.

But a msg came out

Msg from logcat:
2019-09-24 22:41:38.316 18913-18913/com.example.input_que_db I/System.out: [Ljava.lang.String;@576dfb0

I am new to Kotlin too, but I would try:

  1. Have the function return coorAns as its result; or
  2. Declare coorAns outside of the function, and pass it to the function as a parameter.
1 Like

Thanks for your suggestions, I would try and see if it works. Thank you