aspose file tools*
The moose likes Beginning Java and the fly likes Help with HashMaps Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help with HashMaps" Watch "Help with HashMaps" New topic
Author

Help with HashMaps

Michael Duff
Greenhorn

Joined: Mar 13, 2010
Posts: 18
Hello there, I am looking for help with HashMaps.

I got the following code for initializing a HashMap (which is for a language recognizing program). The first HashMap contains the language as key (String), and another hashmap as value. The second hashmap has the letters (in ASCII) as key, and a Vector as value. The Vector will hold the amount of occurences of each letter. I am asking if this is the correct way to initialize it:



And is this the correct way of adding new languages and accessing the components in that kind of HashMap structure?

Also I'd like to ask if there are any alternative ways of achieving the same kind of linked structure?

Cheers,

Michael
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1613
    
  10

I had a similar problem.... I can't find the thread now, but I think the way I fixed the compiler issue I was getting is to get rid of the internal generic declaration on the right side of the expression.

The compiler just cares what the list or map is populated with. If it's populated with lists or maps, great... but it doesn't need to know what the internal list or map has in it.

so this won't work:

But this should:


I think the reasoning for this is the way the declarations of generics work and where they're needed...


When you do things right, people won't be sure you've done anything at all.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

and Welcome to JavaRanch
Michael Duff
Greenhorn

Joined: Mar 13, 2010
Posts: 18
Thanks, and thanks Janeice, think that makes the structure a bit clearer.

But now I face another problem that is Vector, is there any way to make the indexing of the Vector start from something else than 0? I am looking for something like this:



Where count is the amount of a specific character in a text, and percent is the percentage a specific character represents in a text. All I'm getting is IndexOutOfBoundsExceptions... and I seem to be very poor at finding information from internet because I couldn't find anything for this exact problem.

Cheers,

Michael
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1613
    
  10

Hmmm... I don't know much about vectors.... why don't you start a new thread? You'll probably get more responses that way.

And you're welcome!
Bert Wilkinson
Ranch Hand

Joined: Oct 28, 2009
Posts: 33
That's not a great use of a Vector. A Vector is basically just a resizeable array. It sounds like you just want another map, using character as a key and a statistical object as the value. Consider making a simple class to hold the data you want and putting that into your map. Like:


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help with HashMaps
 
Similar Threads
Hashtable with Vectors or HashMap with ArrayLists - please help
LZW Compression / Decompression
2 Synchronization blocks with same object
Please Help: Putting Vector objects into HashMap
HashMap and Vector