I have a code in Java:
for(Iterator it = c.getArrayList().iterator(); it.hasNext(); ) {
Object i = it.next();
// Here I have an error, i is not a boolean
if (i) {
System.out.format("Delete %s%n", i);
it.remove();
}
else {
System.out.println("End");
break;
}
}
But the if
clause throws an error. It expects boolean
but Object
is given. Java cannot transform types, right?
How do I have to change the type or what do I have to put in the if
clause to make it work right?
UPD:
It is a collection (an ArrayList) of Strings.
Object i = it.next(); // I get one element from collection.
if (i) { // check if it's not the end, if it's not the last element of the collection