[crackmonkey] [scheide@usfca.edu: Adding one to a java hashtable]

Nick Moffitt nick at zork.net
Wed Dec 23 19:25:08 PST 1998


----- Forwarded message from Eric Scheide <scheide at usfca.edu> -----

Ok start thinking java.

I'm counting all the individual words in a book.  Like fish appears 30
times etc.  So I made a hashtable key'd by each word with an integer object
as the value.

words is the hash
w is the key (a word)
Look at the stupid crap you have to do to increment the Integer object.
There must be an easier way.  Far as I know a hash table has to take an
object as the value so you cant just use an int number.  It must be an
Interger object.  Seems silly.

 if (words.containsKey(w)) {
   words.put(w,new Integer(((Integer)words.get(w)).intValue()+ 1));
 }

Here's the perl version

$words{$w}++;

sigh.

----- End forwarded message -----

-- 
 * Progress (n.): The process through which Usenet has evolved from
   smart people in front of dumb terminals to dumb people in front of
   smart terminals.  -- obs at burnout.demon.co.uk (obscurity)
=====================================================================
To unsubscribe, send a message to majordomo at zork.net saying
"unsubscribe crackmonkey" in the body of the message.



More information about the Crackmonkey mailing list