Programmers learn & share
0 votes

Problem :

I am getting bellow error 
can only iterate over an array or an instance of java.lang.iterable

by (6.9k points)   | 410 views

1 Answer

0 votes

Solution :

Probably you have not selected the correct method for your for loop. 

You need to break the tiles string down into characters by using toCharArray() instead. 

The indexOf() method will return the position of the char is within the string. And we want to iterate over the string so we need an iterable object that is what your error is saying.

Using toCharArray() converts a string to an iterable array that your for loop can pass over one char at a time.

Further Readings:

by (36.1k points)  
edited by
2,187 questions
2,514 answers
241 users