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

mod rewrite - Using "?" when rewriting the URL -

.htaccess: Transfer name to index.php if not directory public -

Admob integration with pygame in android -