boolean found = false; while (st.hasMoreElements()) { if (st.nextToken().equals(word)) found = true; } if (found) //say it was found else //say it was not found