How to remove element from Hashtable by key 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++"); 
        
        ht.remove(3);
         
        for (Map.Entry m:ht.entrySet()) {  
            System.out.println(m.getKey() + " " + m.getValue());  
        }  
    }
}



/*
run:

6 c
5 c++
4 java
2 c++
1 c#

*/

 



answered Apr 29, 2020 by avibootz

Related questions

1 answer 159 views
1 answer 147 views
1 answer 162 views
162 views asked Feb 20, 2017 by avibootz
1 answer 152 views
1 answer 168 views
2 answers 225 views
1 answer 110 views
...