I am using a TreeMap
to store words of a text and the coordinates (row, column) of each word, TreeMap
it is defined as:
TreeMap<String, Double> mapa= new TreeMap<String, Double>();
My question is the following: can I add more fields to the parameter Double
? so that it would be as follows:
TreeMap<String, Double, Double> mapa= new TreeMap<String, Double, Double>();
and thus be able to enter the <"word", column, row >
No, what you have to do is create a class
Coordenadas
that includes column and rowThen you can use the TreeMap like this
This is incorrect:
since TreeMap only allows 2 arguments ,
where:
K
: Key defined by this mapV
: Value, the type of assigned values, value to which the specified key maps, or null if this map contains no mapping for the key.You can store the information you need, since precisely the TreeMap allows you to store data with a hierarchical structure in key/value pairs (tree structure).
When you want to add more than one value, in this case an object is created in which you can store the values you need.
Example:
To create your Map this would be an example: