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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。