How to read text file faster in ArrayList on Android

I have a problem reading a txt file quickly in an ArrayList. If I want to read a file size of 0.9 MB, I have to wait 5 minutes. If the file size is 34 MB (in part because the android does not accept files larger than 1 MB), it does not work completely. I think the process should be max a few seconds.

This is the code:

String word; 
public ArrayList<String> dictionary = new ArrayList<String>();

public void setup() 
{

  try {
      AssetManager assetManager = getAssets();
      InputStream inputf;
      inputf = assetManager.open("dict_1.txt");
      reader = new BufferedReader(new InputStreamReader(inputf));

      word = " ";      
      while(word != null)
      {
        word =  reader.readLine();

        if (word != null)
          dictionary.add(word);
      }
      if(reader.equals("null")) println("No file found");

    } catch (NullPointerException e) {
    e.printStackTrace();
    println("No file found");
    } catch (IOException e) {
    e.printStackTrace();
    }
}

Sorry for my english. I hope everything will be understated.

+3
source share
2 answers

ArrayList . , , . , ArrayList:

 dictionary = new ArrayList<String>(numberOfEntries);

, Java. UTF-8, ( ).

+2

arraylist In arraylist - - O (1), write backing array, re-allocation a copy - , O (n) time.so linkedlist arraylist. o(1) ( )

LinkedList<String> dictionary = new LinkedList<String>();
+1

All Articles