This is the code which i wrote.But when i input a word,it should search it and give the definition.I think there is a problem in while loop.But i can't solve it.Can u guys,plz check it?

import java.util.*; 

class dictionary
public static void main(String args[])

Hashtable dict = new Hashtable(); 

Enumeration names; 

String str; 

String n;

dict.put("discuss", new String("talk about something")); 

dict.put("encourage", new String("persuade to do")); 

dict.put("thread", new String("a thing string of cotton")); 


// Show all words in hash table. 

names = dict.keys(); 

System.out.println("Enter a word:"+args[0]);




str = (String)names.nextElement(); 

System.out.println(str+ ": " +dict.get(str)); 






names is an Enumeration

n is args[0] which is a String.

An Enumeration and a String can never be equal.

ps: Hashtable is designed for this kind of thing, so it has other methods that you will find very useful... spend 10 minutes reviewing all its methods before choosing which to use.

No, because an Enumeration and a String are completely different things; you can't just cast one to the other.

Hi pro learner ,

Just logged in and see your post about creating a simple dictionary. Though it is a dead post but posting in case you still wishing to have fun with it. Here is some code might help you out.

 import java.util.*;
public class Dictionary {

    public static void main(String[] args) {

        Map <String, String> dictionary;
        dictionary = new TreeMap <String , String>();
        Scanner s = new Scanner (;
        dictionary.put("discuss", "talk about something");
        dictionary.put("fissure", "a narrow opening");
        dictionary.put("spasmodic", "sudden but for short time");
        System.out.println("Enter a word :");
        String search =;


commented: Post is relevant and shows how to avoid legacy data structures. +13