title: How to remove all items from ArrayList in kotlin
body: <p>I have an array list in kotlin and I want to remove all item from it, leave it as an empty array to start adding new dynamic data. i tried <code>ArrayList.remove(index)</code> <code>arrayList.drop(index)</code> but none works, </p>
  
  <p>The Declaration:</p>
  
  <pre><code>var fromAutoCompleteArray: List&lt;String&gt; = ArrayList()
  </code></pre>
  
  <p>here is how I try it :</p>
  
  <pre><code>for (item in fromAutoCompleteArray){
          fromAutoCompleteArray.remove(0)
               }
  </code></pre>
  
  <p>I'm using the <code>addTextChangedListener</code> to remove old data and add new data based on user's input:</p>
  
  <pre><code>    private fun settingToAutoComplete() {
          val toAutoCompleteTextView: AutoCompleteTextView =
              findViewById&lt;AutoCompleteTextView&gt;(R.id.toAutoCompleteText)
          toAutoCompleteTextView.addTextChangedListener(object : TextWatcher {
              override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
              }
  
              override fun afterTextChanged(s: Editable?) {
                  doLocationSearch(toAutoCompleteTextView.text.toString(), 2)
  
              }
  
              override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
                  toAutoCompleteTextView.postDelayed({
                      toAutoCompleteTextView.showDropDown()
                  }, 10)
              }
  
          })
          val adapter = ArrayAdapter(this, android.R.layout.select_dialog_item, toAutoCompleteArray)
          toAutoCompleteTextView.setAdapter(adapter)
          toAutoCompleteTextView.postDelayed({
              toAutoCompleteTextView.setText("")
              toAutoCompleteTextView.showDropDown()
          }, 10)
      }
  </code></pre>
  
  <p>And here is the function that adds the data :</p>
  
  <pre><code>    private fun doLocationSearch(keyword: String, fromTo: Number) {
          val baseURL = "api.tomtom.com"
          val versionNumber = 2
          val apiKey = "******************"
          val url =
              "https://$baseURL/search/$versionNumber/search/$keyword.json?key=$apiKey"
          val client = OkHttpClient()
          val request = Request.Builder().url(url).build()
          client.newCall(request).enqueue(object : Callback {
              override fun onResponse(call: Call, response: okhttp3.Response) {
                  val body = response.body?.string()
                  println("new response is : $body")
                  val gson = GsonBuilder().create()
                  val theFeed = gson.fromJson(body, TheFeed::class.java)
                  if (theFeed.results != null) {
                      for (item in theFeed.results) {
                          println("result address ${item.address.freeformAddress} ")
                          if (fromTo == 1) {
                              fromAutoCompleteArray = fromAutoCompleteArray + item.address.freeformAddress
                              println(fromAutoCompleteArray.size)
                          } else {
                              toAutoCompleteArray = toAutoCompleteArray + item.address.freeformAddress
                          }
                      }
                  } else {
                      println("No Locations found")
                  }
  
  
              }
  
              override fun onFailure(call: Call, e: IOException) {
                  println("Failed to get the data!!")
              }
          })
  
      }
  </code></pre>
  
  <p>and as you see the line <code>println(fromAutoCompleteArray.size)</code> shows me if it's deleted or not, and it is always encreasing.</p>
  
  <p>Also, tried to use <code>clear()</code> without a loop and none works:</p>
  
  <p><code>fromAutoCompleteArray.clear()</code></p>