Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
Contributor
Posts: 30
Registered: ‎04-13-2013
My Device: blackberry bold
My Carrier: developer

How to retrieve the key based on its value in hashtable?

Hey

 

I know its very basic question. But still i am not able to solve it.

 

Hashtable table = new Hashtable();

table.put("k1","v1");

table.put("k2","v2");

table.put("k3","v3");

table.put("k4","v1");

 

I want to retrieve the keys having value v1.

How to do this??

 

Developer
Posts: 17,019
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: How to retrieve the key based on its value in hashtable?

get is the counterpart of put.
table.get("k1") would return "v1".
note that get returns an Object, as you know it is a string you can cast it that way.
String v1 = (String) table.get("k1"); //v1 has the content "v1" now
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Contributor
Posts: 30
Registered: ‎04-13-2013
My Device: blackberry bold
My Carrier: developer

Re: How to retrieve the key based on its value in hashtable?

Hey

I want to get all those keys whise value is v1.

I want to calculate keys according to values.

Developer
Posts: 17,019
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: How to retrieve the key based on its value in hashtable?

hashtable is not really the correct data structure for that task.
take a look at
http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/util/MultiMap.html
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter