Q:

How to check if(Object) in Java?

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

A:

Are you trying to test whether it's null?
if (i != null) {
    System.out.format("Delete %s%n", i);
    it.remove();
}
else {
    System.out.println("End");
    break;
}

If you're checking the boolean value of i and the ArrayList is a List<Boolean>, then you can use Iterator<Boolean> it, but you still have to be careful of null pointer exceptions.

Edit: If you want to print End when all the non-null strings are removed, then you can delete the else block and just print End after the for loop.

