Purchase Solution

Java Hashtables

Not what you're looking for?

Ask Custom Question

We are working on hashtables and I am trying to figure out a real life example that could be solved with hashtables to jtree as well as some type of array or jlist. I just need some opinions or examples of this part please.

Here is an exercise I do not understand in this chapter.

Observe the following code, which creates a simple hashtable.
// Demonstrate a Hashtable
import java.util.*;
class HTDemo
{
public static void main(String args[])
{
Hashtable<String,Integer> numbers = new
Hashtable<String,Integer>();

numbers.put("one", new Integer(1));
numbers.put("two", new Integer(2));

}
}

Starting with this provided code, add the following functionality:
1. Add the numbers 3 through 10 to the hashtable continuing in the same manner as shown.
2. Prompt the user for a string, and display the corresponding number. For example, if the user types "five", the program would output "5". This must be done using the hashtable as created in the previous step.
3. Using a loop and a single printlng statement, display all of the values (both strings and integers) in a table.

Purchase this Solution

Solution Summary

This solution provides a simple example of using a HashTable. It shows how to insert elements into a hash table. It also shows how to use an Enumeration to iterate over all of the elements of the table.

Solution Preview

The first part of this solution requires adding additional "add()"
method calls as follows:

<pre>
numbers.put("three", new Integer(3));
numbers.put("four", new Integer(4));
numbers.put("five", new Integer(5));
numbers.put("six", new Integer(6));
numbers.put("seven", new Integer(7));
numbers.put("eight", new Integer(8));
numbers.put("nine", new ...

Purchase this Solution


Free BrainMass Quizzes
Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

Javscript Basics

Quiz on basics of javascript programming language.

Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.

C# variables and classes

This quiz contains questions about C# classes and variables.