Hi everbody,
Seen posts saying simple dictionary in Java. Thought of sharing something may be useful for others. Here is a simple code if anyone interested.

 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 (System.in);
        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 = s.next();



       if(dictionary.containsKey(search)){

       System.out.println(dictionary.get(search));
       } 
    }
}

Recommended Answers

All 2 Replies

the problem with most applications: if it's "simple", it's usually .. well, lousy.
a few issues with this code: if you want to add, or correct a definition of a word, you have to recompile your code.
you could read both word and definition in from a .txt file, which you can adjust without having to recompile your code.

Thanks for replying to the post. You pointed out a big issue in this code but to be honest I posted this code because someone else in this forum something much similar to this. I know that there could several different changes could be done to make this program work better for the user. Anyway thanks for your suggestion.

Peace

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.