I am making an app for android devices. There is a function in my app which has 2 "for loops" which iterate 3200 times each, accessing a 53 KB .txt file(which contains 3200 lines) and compare a string with each line, one line per iteration. The "for loops" also contain BufferedReader(), InputStreamReader(), InputStream() and StringTokenizer(). So it takes around 8 seconds for it to process that function, when I run the app on the emulator. This is inacceptable. How can I reduce the time required to, like, half a second, or max. 1 second? Thanks! edit:Here's is the part of my program with the 2 for loops:
else if(a==2){
String z="";
try{
InputStream is = getAssets().open("USCOUNTIES.txt");
InputStreamReader iz=new InputStreamReader(is);
BufferedReader bis = new BufferedReader(iz);
int v=0;
v=count("USCOUNTIES.txt");//counts number of lines in the .txt file
//finding no. of counties to be displayed
int counter=0;
String pos;
pos=Integer.toString(position);
try{
for(int i=0;i<v;i++){
z=bis.readLine();
//int x=pos.length();
boolean a;
//using stringtokenizer
StringTokenizer st = new StringTokenizer(z, ",");
String substring;
substring=(String) st.nextElement();
a=substring.equals(pos);
if(a==true){
counter=counter+1;
}
}}catch(Exception e){e.printStackTrace();}
String array1[]=new String[counter];
try{
InputStream ig = getAssets().open("USCOUNTIES.txt");
InputStreamReader ia=new InputStreamReader(ig);
BufferedReader bos = new BufferedReader(ia);
int j=0;
for(int i=0;i<v;i++){
z=bos.readLine();
String[] split = z.split(",");
if(split[0].equals(pos)){
array1[j]=split[1];
j=j+1;
}
}}
catch(Exception e){e.printStackTrace();}