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?
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.
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.
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: