• Register
search
Log In
0 votes
473 views

Problem :

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

6.9k points

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:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=400624

36.1k points
edited by

Related questions

1 vote
1 answer 151 views
151 views
Problem : I am very new to programming. I need to write a program called swapAdj that must accept the array of integers and after that swap those elements at the adjacent indexes. For example consider the elements 0 and 1 are swapped by the program and after ... note if your array has the odd length then the program must keep final element unmodified. Please help me in writing above program.
asked Apr 7 morrisBson 3.2k points
0 votes
1 answer 61 views
61 views
Problem : java does not limit the number of dimensions that an array may have
asked Nov 1, 2019 peterlaw 6.9k points
3 votes
2 answers 21 views
21 views
Problem: I am struggling with a problem for a few hours back. I know how to sort an array by using methods. I was looking for another way (perhaps a loop) to do it more efficiently. Let me put my question this way, how to sort an array in java without using sort method? Could anybody here please help to make this happen? Thanks in advance
asked Mar 24 Gavin 15k points
0 votes
1 answer 248 views
248 views
I am getting an issue where my deployable jar hits an exception : can not deserialize instance of java.lang.string out of start_object token
asked Oct 23, 2019 peterlaw 6.9k points
0 votes
1 answer 11 views
11 views
Problem: Hello kodlogs, How can we use for loop in the python to iterate over the sequence of element I have a confusion over the range() function and the datatype like list, tuple and string. Like how can we access the elements in the list
asked Jun 9 Gavin 15k points