import java.util.*;
class Node2 implements Comparable<Node2> {
int d = Integer.MAX_VALUE;
Node2 previous = null;
int x;
int y;
List<Node> nodeAdj = new ArrayList();
public int compareTo(Node2 node2) {
if (this.d > node2.d) {
return 1;
}
if (this.d == node2.d) {
return 0;
}
return -1;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Node2 node2 = (Node2) o;
return d == node2.d;
}
@Override
public int hashCode() {
// System.out.println("11111111111111111");
// System.out.println(d);
int t=Objects.hash(d);
// System.out.println("hash:"+t);
// System.out.println("22222222222222");
return t;
}
public String toString() {
return "[" + x + "," + y + "]";
}
}
public class TestPriorityQueue {
public static void main(String [] args)
{
HashSet<Node2> hashSet=new HashSet<>();
List<Node2> list=new ArrayList<>();
for(int i=0;i<2;i++)
{
Node2 node2=new Node2();
node2.d=5;
node2.d=new Random().nextInt(1000);
hashSet.add(node2);
list.add(node2);
}
for( Node2 node2:list)
{
node2.d=5;
boolean yyy=hashSet.contains(node2);
System.out.println("contains "+yyy);
boolean xxx= hashSet.add(node2);
System.out.println("added "+xxx);
}
for( Node2 node2:hashSet)
{
System.out.println(node2.d);
}
}
}
//output
contains false
added true
contains true
added false
5
5
5
java 容器
最新推荐文章于 2022-08-09 14:44:03 发布