How to print Hashtable in Java

1 Answer

0 votes
import java.util.*;  
 
public class MyClass {
    public static void main(String args[]) {
        Hashtable<Integer, String> ht = new Hashtable<Integer, String>();
      
        ht.put(4, "java");
        ht.put(6, "c");
        ht.put(1, "c#");
        ht.put(3, "python");
        ht.put(2, "c++");
        ht.put(5, "c++"); 
          
        for (Map.Entry m:ht.entrySet()) {  
            System.out.println(m.getKey() + " " + m.getValue());  
        }  
    }
}
 
 
 
/*
run:
 
6 c
5 c++
4 java
3 python
2 c++
1 c#
 
*/

 



answered Apr 29, 2020 by avibootz

Related questions

1 answer 110 views
1 answer 165 views
2 answers 172 views
172 views asked Apr 29, 2020 by avibootz
1 answer 132 views
132 views asked Apr 28, 2020 by avibootz
2 answers 192 views
3 answers 234 views
...