0% found this document useful (0 votes)
5 views1 page

Dictionary Hansh Map Java

The document is a Java program that implements a simple dictionary using a HashMap to store words and their definitions. It allows adding entries, retrieving definitions, checking for the existence of words, printing all entries, and removing specific entries. The program demonstrates these functionalities with example words like 'Apple', 'Banana', and 'Java'.

Uploaded by

rachi.website
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Dictionary Hansh Map Java

The document is a Java program that implements a simple dictionary using a HashMap to store words and their definitions. It allows adding entries, retrieving definitions, checking for the existence of words, printing all entries, and removing specific entries. The program demonstrates these functionalities with example words like 'Apple', 'Banana', and 'Java'.

Uploaded by

rachi.website
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.util.

HashMap;

public class Dictionary {

public static void main(String[] args) {


// Create a HashMap where the key is the word and the value is its
definition
HashMap<String, String> dictionary = new HashMap<>();

// Add entries (word, definition)


dictionary.put("Apple", "A round fruit with red, green, or yellow skin and
a whitish interior.");
dictionary.put("Banana", "A long, curved fruit with a yellow skin and soft,
sweet, white flesh inside.");
dictionary.put("Java", "A high-level, class-based, object-oriented
programming language.");
dictionary.put("HashMap", "A map implementation that stores key-value pairs
using hashing.");

// Retrieve a definition based on a word


System.out.println("Definition of Apple: " + dictionary.get("Apple"));
System.out.println("Definition of Java: " + dictionary.get("Java"));

// Check if a word exists in the dictionary


String wordToFind = "Python";
if (dictionary.containsKey(wordToFind)) {
System.out.println("Definition of " + wordToFind + ": " +
dictionary.get(wordToFind));
} else {
System.out.println(wordToFind + " is not found in the dictionary.");
}

// Print all words and their definitions in the dictionary


System.out.println("\nComplete Dictionary:");
for (String word : dictionary.keySet()) {
System.out.println(word + ": " + dictionary.get(word));
}

// Removing an entry from the dictionary


dictionary.remove("Banana");
System.out.println("\nAfter removing Banana:");
for (String word : dictionary.keySet()) {
System.out.println(word + ": " + dictionary.get(word));
}
}
}

You might also like