Fecthing the Key Name from a HashTable

key value in hashtable , asp.net hashtable , hashtable and asp.net , hashtables in csharp Toronto, Canada
  • 12 years ago
    hi, Can anyone tell me how can I list the key names in a hashtable. To access a value of a given key is simple(HashTable["key"].tostring()). But I want to list all the keys in a hashtable. how can that be possible. Regards Royal
  • 12 years ago
    Hi, you can do that by using the keys property. Regards Simon C
  • 12 years ago
    hi, I did it using the combination of ICollection & ArrayList. Thanks Regards, Royal
  • 12 years ago
    Hi, yes, it can be done by an ArrayList import java.util.ArrayList; import java.util.HashMap; public class Test { public static void main(String[] args) { Object anObject = new Object(); Object anotherObject = new Object(); HashMap hm = new HashMap(); ArrayList keyList = new ArrayList(); hm.put("Key1", anObject); hm.put("Key2", anotherObject); keyList.addAll(hm.keySet()); System.out.println(keyList); } } The Result: [Key2, Key1]

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“There are only two kinds of languages: the ones people complain about and the ones nobody uses” - Bjarne Stroustrup