如果没有覆盖hashCode()方法,那么在Java中的任何对象上调用hashCode()的结果是什么?
hashCode()方法在java中返回什么值?
我读到它是一个对象的内存引用...当我打印哈希值为new Integer(1)1时; 因为String("a")是97.
我很困惑:它是ASCII还是什么类型的值?
我在这里没有找到任何关于这个问题的线索。我正在尝试使用 java 流删除一个列表 (cars1) 中存在于另一个列表 (cars2) 中的元素(在我的例子中为汽车)。我尝试使用removeIf,但后来感觉它更适合字符串列表等。
Car c1 = new Car();
c1.id = 1;
c1.name = "C1";
Car c2 = new Car();
c2.id = 2;
c2.name = "C2";
List<Car> cars1 = new ArrayList<Car>();
cars1.add(c1);
cars1.add(c2);
List<Car> cars2 = new ArrayList<Car>();
cars2.add(c2);
// TODO : Remove all the cars from cars1 list that are in cars2 list using java streams
Run Code Online (Sandbox Code Playgroud)