Can we use integer as a key for the string in the HASHMAP?

Recommended Answers

If you want to use an integer as a key in a Map you'll need to use a primitive wrapper.

Here's an example of that:

Map<Integer, String> map;

Note that the following is not valid:

Map<int, String> map; // invalid
Jump to Post

All 2 Replies

If you want to use an integer as a key in a Map you'll need to use a primitive wrapper.

Here's an example of that:

Map<Integer, String> map;

Note that the following is not valid:

Map<int, String> map; // invalid