weakhashmap
WeakHashMap类的remove()方法 (WeakHashMap Class remove() method)
remove() method is available in java.util package.
remove()方法在java.util包中可用。
remove() method is used to delete or remove the mappings for the given key element (key_ele) when it exists.
remove()方法用于删除或删除给定键元素(key_ele)存在时的映射。
remove() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
remove()方法是一种非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。
remove() method does not throw an exception at the time of removing an element.
remove()方法在删除元素时不会引发异常。
Syntax:
句法:
public Object remove(Object key_ele);
Parameter(s):
参数:
Object key_ele – represents the key element (key_ele) whose linking element is to be deleted.
对象key_ele –表示要删除其链接元素的键元素(key_ele)。
Return value:
返回值:
The return type of the method is Object, it returns the associated value for the given key element (key_ele) when exists otherwise it returns null.
方法的返回类型为Object ,如果存在则返回给定键元素(key_ele)的关联值,否则返回null。
Example:
例:
// Java program to demonstrate the example
// of Object remove(Object key_ele)
// method of WeakHashMap
import java.util.*;
public class RemoveOfWeakHashMap {
public static void main(String[] args) {
// Instantiates a WeakHashMap object
Map < Integer, String > map = new WeakHashMap < Integer, String > ();
// By using put() method is to add
// key-value pairs in a WeakHashMap
map.put(10, "C");
map.put(20, "C++");
map.put(50, "JAVA");
map.put(40, "PHP");
map.put(30, "SFDC");
// Display WeakHashMap
System.out.println("WeakHashMap: " + map);
// By using remove() method is to remove
// the mappings exists for the given key
// element in this WeakHashMap
map.remove(50);
// Display Modified WeakHashMap
System.out.print("map.remove(50): " + map);
}
}
Output
输出量
WeakHashMap: {30=SFDC, 40=PHP, 10=C, 20=C++, 50=JAVA}
map.remove(50): {30=SFDC, 40=PHP, 10=C, 20=C++}
翻译自: https://www.includehelp.com/java/weakhashmap-remove-method-with-example.aspx
weakhashmap