tell me the best way to write a contains method in java linkedlist?

It’s always returning false because list is a List and i is an int, so they can’t be equal, since they aren’t the same type.

You probably want to wrap a for loop around your search body

public static boolean search(int i) {
    for(int item : list)
        if(item == i) return true;
    return false;

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top