performance - convert string array into integer array android -


i created url string array.

string urls[]={"http://www.kllhjj.png","http://yui.kl.png"}; 

this url not correct. in code them correct. try convert them integer array following way.

int a[] = new int[urls.length];  for(int i=0; i<a.length; i++) {    try {       a[i] = integer.parseint(urls[i]);    }    catch(exception e) { } } 

but here show integer values 0. why it? me

because integer.parseint(urls[i]); throwing numberformatexception , you swallowing exception . below code not work in case, @ least know error:

try{      a[i]=integer.parseint(urls[i]);    }catch(exception e){      e.printstacktrace();      throw new runtimeexception(e);  } 

all elements of primitive int array defaulted 0. hence 0s .

you cannot parse string "http://yui.kl.png" etc int not in numeric format . read documentation:

throws:

numberformatexception - if string not contain parsable integer.


Comments