• Register
0 votes
737 views

Problem :

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

6 5 3
6,930 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

9 7 4
38,600 points

Related questions

1 vote
1 answer 252 views
252 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 69 views
69 views
Problem : java does not limit the number of dimensions that an array may have
asked Nov 1, 2019 peterlaw 6.9k points
0 votes
1 answer 12 views
12 views
I want to know how to sort an array in java without using sort method.
asked Sep 28 Daniel Anderson 4k points
3 votes
2 answers 1.5K views
1.5K 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 15.3k points
0 votes
1 answer 18 views
18 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 15.3k points