public class MyIterable implements Iterable<String>{
private List<String> strings;
//constructor that initializes the string field with the provided list
public MyIterable(list<String> strings){
this.strings = strings;
}
//Iterator method taht returns on iterator for the strings list
public Iterator<String> iterator(){
return strings.iterator();
}
}
Encounter with an error called Challenge not yet complete in Empathetic Impala Playground
We can't find the debug log with the string ‘Hello’.
Can anyone pls help me on this issue!!!!
#Trailhead Challenges
Hello @margam mamatha
,
Try to use this code:
Apex Class:
public class MyIterable implements Iterable<String> {
Private List<String> strings;
// Constructor to initilize the list of strings
public MyIterable(List<String> strings)
{
this.strings = strings;
}
// Implementing the iterator method
public Iterator<String> iterator(){
return strings.iterator();
}
}
Test Class:
@IsTest
public class MyIterableTest {
@IsTest
static void testIterableForLoop(){
// Create a list of strings
List<String> strings = new List<String> {'Hello', 'World'};
// Create an Instance of MyIterable
MyIterable myIterable = new MyIterable(strings);
// Use a for loop to iterate over the MyIterable instance
for(String str: myIterable){
//Print each string to the debug log
System.debug(str);
}
}
}
After saving the Apex Class and Test Class, click "Run Test".