You don't need two arrays.

  • Create a master array.
  • Sort it.
  • As the characters are typed you just need to record the first element and the count of matches
  • Using the start and the count you can pull out the information as you wish.


Because the list is sorted and you are doing simple prefix match this will work well. If you were using pattern matching or searching anywhere in the string you would have to construct an extract array.