• Register
0 votes

Problem :

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

6.9k points

Please log in or register to answer this question.

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:


38.6k points
edited by