package com.yiibai; import java.util.*; public class HashMapDemo { public static void main(String args[]) { // create hash map HashMap newmap = new HashMap(); // populate hash map newmap.put(1, "tutorials"); newmap.put(2, "point"); newmap.put(3, "is best"); System.out.println("Values before remove: "+ newmap); // remove value for key 2 newmap.remove(2); System.out.println("Values after remove: "+ newmap); }}
控制台输出:
Values before remove: {1=tutorials, 2=point, 3=is best} Values after remove: {1=tutorials, 3=is best}
java.util.HashMap.remove()方法的使用
最新推荐文章于 2022-03-25 17:30:41 发布