What does this error mean? and how to solve it?
foreach is not an expression type.
im trying to write find () method. that find a string in a linked list
public class Stack<Item> { 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 find { public static void main( String[] args ) { Stack<String> s = new Stack<String>(); String key = "be"; while( !StdIn.isEmpty() ) { String item = StdIn.readString(); if( !item.equals("-") ) s.push( item ); else StdOut.print( s.pop() + " " ); } s.find1( s, key ); } public boolean find1( Stack<String> s, String key ) { for( String item : s ) { if( item.equals( key ) ) return true; } return false; } }
this is all my code
source share