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 168 views
1 answer 155 views
1 answer 177 views
177 views asked Feb 20, 2017 by avibootz
1 answer 173 views
2 answers 235 views
1 answer 163 views
1 answer 117 views
...