JAVA - find element in linked list
<p>I need to solve this problem:</p>

<p>Write a method <code>find()</code> that takes an instance of <code>Stack</code> and
a <code>String</code> <code>key</code> as arguments and returns <code>true</code> if some node in the list has <code>key</code> as
its <code>item</code> field, <code>false</code> otherwise. Test your function in a test client. This test
client may be the main function in the class <code>Stack</code>.</p>

<p>In Java, this is what I've got so far:</p>

<pre><code>public class Stack&lt;Item&gt;
{
    private Node first;

    private class Node
    {
    Item item;
    Node next;
    }

    public boolean isEmpty()
    {
    return ( first == null );
    }

    public void push( Item item )
    {
    Node oldfirst = first;
    first = new Node();
    first.item = item;
    first.next = oldfirst;
    }

    public Item pop()
    {
    Item item = first.item;
    first = first.next;
    return item;
    }

    public static void main( String[] args )
    {
    Stack&lt;String&gt; collection = new Stack&lt;String&gt;();

    String key = "be";

    collection.find( key );

    while( !StdIn.isEmpty() )
        {
        String item = StdIn.readString();
        if( !item.equals("-") )
            collection.push( item );
        else 
            StdOut.print( collection.pop() + " " );
        }
    }

    public void find( String key )
    {   
    for( Node x = first; x != null; x = x.next )
        {
        if( x.item == key )
            StdOut.println( x.item );
        }
    }
}
</code></pre>
