When should I use HashMap instead of creating a Class? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

When should I use HashMap instead of creating a Class?

It seems that HashMap is less useful and its use may be done with a Class, so why use it?

28th Jun 2017, 7:49 PM
igokra
igokra - avatar
2 Respostas
+ 1
Hasmap is a good collection. Use it when you need associate values to key. Its easier than create a class because its generic parameters. An exaple of using map: If you have class A and B , make in class B a Map<Integer,A> what stores A objects by ID. In classB you can search A objects by ID.
28th Jun 2017, 8:17 PM
SzabĆ³ GĆ”bor
SzabĆ³ GĆ”bor - avatar
+ 1
Thanks!
28th Jun 2017, 8:31 PM
igokra
igokra - avatar