I want to make a dictionary in JAVA
how it is done in python
and I see that it is not the same...
Search a bit and I think it can be done with HashMap
but it still throws me an error:
HashMap dict = new HashMap(String, Int)(); --> can't but
HashMap dict = new HashMap(String, String)(); -> yes you can
So, how do I put together an easy dictionary where I store, for example:
Names and exam marks...?
Try this:
You can find more information here.
An equivalent of Python dictionaries in Java would be a HashMap where you can also store elements defined by key (key) and value (value).
Actually this can be done:
It only depends on the types that you define for key (key) and value (value) that your HashMap will use , in this case you would define it in this way:
You can use several options, for example:
Using Java 8, you can do it this way:
HashMap has the implementation of the form (key, value) such as:
more info and examples here