Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Hashtable

Reply
Thread Tools

Hashtable

 
 
tuurbo46@yahoo.co.uk
Guest
Posts: n/a
 
      01-24-2006
Hi

Im currently im in a bit of a corner. I am able to put data in a
hashtable, but now im in a muddle getting the data out.

How do i change the below method to retrive the data without using the
string?

// declared at top of source file
private TextField userName = new
TextField("Name:.","",20,TextField.ANY);
private TextField userNumber = new
TextField("Number:.","",20,TextField.ANY);

//Declaration of hashtable
Hashtable hT = new Hashtable(5);

//method in code
public void View()
{
Enumeration e1=hT.keys();
while(e1.hasMoreElements())
{
userName=(String)e1.nextElement();
userNumber=(String)hT.get(userName);
display.setCurrent(userNumber);
}
}

 
Reply With Quote
 
 
 
 
Oliver Wong
Guest
Posts: n/a
 
      01-24-2006

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ps.com...
> Hi
>
> Im currently im in a bit of a corner. I am able to put data in a
> hashtable, but now im in a muddle getting the data out.
>
> How do i change the below method to retrive the data without using the
> string?
>
> // declared at top of source file
> private TextField userName = new
> TextField("Name:.","",20,TextField.ANY);
> private TextField userNumber = new
> TextField("Number:.","",20,TextField.ANY);
>
> //Declaration of hashtable
> Hashtable hT = new Hashtable(5);
>
> //method in code
> public void View()
> {
> Enumeration e1=hT.keys();
> while(e1.hasMoreElements())
> {
> userName=(String)e1.nextElement();
> userNumber=(String)hT.get(userName);
> display.setCurrent(userNumber);
> }
> }


If you don't care about the keys, use the values() method instead of the
keys() method to get an enumeration of values.

Are you using Java 1.5 or 1.4 or some other version?

- Oliver


 
Reply With Quote
 
 
 
 
zero
Guest
Posts: n/a
 
      01-24-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote in news:1138125463.066937.5490
@f14g2000cwb.googlegroups.com:

> Hi
>
> Im currently im in a bit of a corner. I am able to put data in a
> hashtable, but now im in a muddle getting the data out.
>
> How do i change the below method to retrive the data without using the
> string?
>
> // declared at top of source file
> private TextField userName = new
> TextField("Name:.","",20,TextField.ANY);
> private TextField userNumber = new
> TextField("Number:.","",20,TextField.ANY);
>
> //Declaration of hashtable
> Hashtable hT = new Hashtable(5);
>
> //method in code
> public void View()
> {
> Enumeration e1=hT.keys();
> while(e1.hasMoreElements())
> {
> userName=(String)e1.nextElement();
> userNumber=(String)hT.get(userName);
> display.setCurrent(userNumber);
> }
> }
>
>


userName is a TextField, so why are you casting the retrieved element to
String? What's TextField anyway? java.awt.TextField has no constructor
that matches what you're using.

Using Hashtable is easy, you just have to make sure that what you put in
matches what you're trying to get out. You can't put in an Acorn and
expect to get an Oak back.

Hashtable table = new Hashtable();
table.put("1", new Integer(1));
table.put("2", new Integer(2));

for (Enumeration e = table.keys(); e.hasMoreElements(); )
{
String key = e.nextElement();
Integer value = (Integer)table.get(key);
System.out.println(key " => " value);
}

 
Reply With Quote
 
tuurbo46@yahoo.co.uk
Guest
Posts: n/a
 
      01-24-2006
Hi

Im currently using jBuilder 9 and J2me within this enviroment. The
(System.out....) value is not used. Would i use the below code now?
Also the J2me enviroment does not like ( " => "), does anybody have any
ideas


for (Enumeration e = table.keys(); e.hasMoreElements(); )
{
String key = e.nextElement();
Integer value = (Integer)table.get(key);
display.setCurrent(key " => " value);
}

 
Reply With Quote
 
Oliver Wong
Guest
Posts: n/a
 
      01-24-2006
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> Hi
>
> Im currently using jBuilder 9 and J2me within this enviroment. The
> (System.out....) value is not used. Would i use the below code now?
> Also the J2me enviroment does not like ( " => "), does anybody have any
> ideas
>
>
> for (Enumeration e = table.keys(); e.hasMoreElements(); )
> {
> String key = e.nextElement();
> Integer value = (Integer)table.get(key);
> display.setCurrent(key " => " value);
> }
>


You should probably specify that you're using J2ME. If you don't say
anything, people might think you're using J2SE, and the libraries are
different between J2ME and J2SE.

The problem with " => " is that you need to add the + operator to do
string concatenation. Try something like this:

<code>
for (Enumeration e = table.keys(); e.hasMoreElements(); )
{
String key = e.nextElement();
Integer value = (Integer)table.get(key);
display.setCurrent(key + " => " + value);
}
</code>

- Oliver


 
Reply With Quote
 
zero
Guest
Posts: n/a
 
      01-24-2006
"Oliver Wong" <(E-Mail Removed)> wrote in news:YLuBf.109771$AP5.28395
@edtnps84:

> The problem with " => " is that you need to add the + operator to do
> string concatenation.


duh on me
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      01-24-2006
On 24 Jan 2006 09:57:43 -0800, (E-Mail Removed) wrote, quoted or
indirectly quoted someone who said :

>Im currently im in a bit of a corner. I am able to put data in a
>hashtable, but now im in a muddle getting the data out.


see http://mindprod.com/jgloss/hashtable.html
and http://mindprod.comj/jgloss/hashmap.html
which is the modern replacement.

for sample code.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      01-24-2006
On 24 Jan 2006 10:25:47 -0800, (E-Mail Removed) wrote, quoted or
indirectly quoted someone who said :

> display.setCurrent(key " => " value);


You a NetRexx coder?
I wonder about the possibility of someday allowing either space or
some other than + character as the concatenation operator, perhaps _
or # or maybe even :
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
Oliver Wong
Guest
Posts: n/a
 
      01-24-2006

"Roedy Green" <(E-Mail Removed) > wrote in
message news:(E-Mail Removed)...
> On 24 Jan 2006 10:25:47 -0800, (E-Mail Removed) wrote, quoted or
> indirectly quoted someone who said :
>
>> display.setCurrent(key " => " value);

>
> You a NetRexx coder?
> I wonder about the possibility of someday allowing either space or
> some other than + character as the concatenation operator, perhaps _
> or # or maybe even :


A few languages use the period character. In a language I'm developing,
it's the ~ character. E.g. "Hello"~" world!"; my rational is that it's about
as difficult to type as the + character on a QWERTY keyboard (shift, and
then one of the two edges of the top most row), and the shape of the
character is vaguely reminiscent of using a string to tie two things
together.

- Oliver


 
Reply With Quote
 
Stefan Ram
Guest
Posts: n/a
 
      01-24-2006
"Oliver Wong" <(E-Mail Removed)> writes:
>A few languages use the period character. In a language I'm
>developing, it's the ~ character. E.g. "Hello"~" world!"; my
>rational is that it's about


I am using in also in a language, I'm developing, namely
in Unotal, for the same purpose. [1]

I took this solution from Perl 6, where the tilde ~ also is
used for string concatenation.

[1]
Section "5.1" (with some typos) in
http://www.purl.org/stefan_ram/html/....html#anchor14

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: hashtable or map? (map inserts not behaving as I expect - and I cant find a decent simple example for hashtable) Kai-Uwe Bux C++ 1 12-21-2008 09:25 PM
Problem with hashTable Guillermo Perl 1 03-04-2004 12:43 PM
Type Hashtable not defined diya ASP .Net 1 10-31-2003 06:59 PM
Get Hashtable Object Directly John E ASP .Net 1 10-08-2003 12:40 PM
vbc compilation fails when using Hashtable Jonathan Wolfson ASP .Net 1 06-27-2003 04:40 PM



Advertisments