ConcurrentHashMap 類的 elements() 方法比較指定對象與此映射是否相等,如果給定對象是與此映射具有相同映射的映射,則返回 true。
用法
public boolean equals(Object o)
參數
o - 要與此映射進行相等性比較的對象
返回
如果指定的對象等於此映射,則返回 true。
拋出
不會拋出任何異常。
例子1
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
public class ConcurrentHashMapequalsExample1 {
public static void main(String args[]) {
ConcurrentHashMap<String , String> mymap = new ConcurrentHashMap<String ,String>();
ConcurrentHashMap<String , String> mymap2 = mymap;
mymap.put("AA", "Java");
mymap.put("BB", "angular");
mymap.put("CC", "JavaScript");
System.out.println("comparing mymap and mymap2:" +mymap.equals(mymap2));
}
}
輸出:
comparing mymap and mymap2:true
例子2
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
public class ConcurrentHashMapequalsExample2 {
public static void main(String args[]) {
ConcurrentHashMap<String , String> mymap = new ConcurrentHashMap<String ,String>();
ConcurrentHashMap<Integer , Integer> mymap2 = new ConcurrentHashMap<Integer , Integer>();
mymap2.put(1, 101);
mymap2.put(2, 102);
mymap2.put(3, 103);
mymap.put("AA", "Java");
mymap.put("BB", "angular");
mymap.put("CC", "JavaScript");
System.out.println("comparing mymap and mymap2:" +mymap.equals(mymap2));
}
}
輸出:
comparing mymap and mymap2:false
相關用法
- Java ConcurrentHashMap elements()用法及代碼示例
- Java ConcurrentHashMap entrySet()用法及代碼示例
- Java ConcurrentHashMap contains()用法及代碼示例
- Java ConcurrentHashMap newKeySet()用法及代碼示例
- Java ConcurrentHashMap forEach()用法及代碼示例
- Java ConcurrentHashMap putIfAbsent()用法及代碼示例
- Java ConcurrentHashMap computeIfAbsent()用法及代碼示例
- Java ConcurrentHashMap isEmpty()用法及代碼示例
- Java ConcurrentHashMap putAll()用法及代碼示例
- Java ConcurrentHashMap mappingCount()用法及代碼示例
- Java ConcurrentHashMap merge()用法及代碼示例
- Java ConcurrentHashMap hashcode()用法及代碼示例
- Java ConcurrentHashMap containsKey()用法及代碼示例
- Java ConcurrentHashMap put()用法及代碼示例
- Java ConcurrentHashMap computeIfPresent()用法及代碼示例
- Java ConcurrentHashMap toString()用法及代碼示例
- Java ConcurrentHashMap replace()用法及代碼示例
- Java ConcurrentHashMap clear()用法及代碼示例
- Java ConcurrentHashMap size()用法及代碼示例
- Java ConcurrentHashMap remove()用法及代碼示例
注:本文由純淨天空篩選整理自 Java ConcurrentHashMap equals() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。