java - My program gives an index out of bounds error -


int i=0;     while(!a.isempty()) {              if(a.tochararray()[i]==' ') {          system.out.println(a.tochararray()[i]);              }              i++;      }      

when run program it's giving me error: index out of bounds. how can solve it?

you're not changing a in loop, a.isempty() not change , you'll continue looping until i goes out of bounds. did mean:

while (i < a.length()) { 

and aside, a.tochararray()[i] can (and should) a.charat(i) (as @martijncourteaux points out).


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -