+ 1

Key from a Value in Java?

Am I to understand there's no simple way to get a Key from a Value? There are entire Stackoverflow debates over best practices and workarounds but they're making my head spin🤯 Please take a glance at my code and let me know if I'm missing something in the Hashmap lessons. Keep in mind my experience level is low🤓 Thanks 😊 https://code.sololearn.com/cPRILC2BHT0u/?ref=app

24th Oct 2019, 11:41 PM
will
will - avatar
3 Réponses
+ 3
System.out.println(band.get("banjo")); Here you get null because the get() method expects a key. "banjo" is a value. System.out.println(band.get("Bubba")); //output banjo Another possibility to get the keys: https://code.sololearn.com/c7BrlKiE1Uxp/?ref=app
25th Oct 2019, 12:19 AM
Denise Roßberg
Denise Roßberg - avatar
+ 2
Yes. That's the sense of a map.
25th Oct 2019, 9:44 AM
Denise Roßberg
Denise Roßberg - avatar
+ 1
Thank you for your response, Denise Roßberg , so am I to understand from your answer that trying to get the key by calling the value is the problem? That you can only, ever, get a value by calling a key, and not the other way around?
25th Oct 2019, 2:59 AM
will
will - avatar