确保你的Device类实现equals和hashCode方法正确。
例如,如果您创建 2 个Device具有完全相同数据的对象,除非设备已实现,否则它们将不会被ObservableArrayList(或任何列表)视为相同。equals/hashCode
请参见下一个示例:
public class ObsListTest {
    static class Device {
        int value;
        public Device(int value) {
            this.value = value;
        }
    }
    public static void main(String[] args) {
        ObservableList<Device> list = FXCollections.<Device>observableArrayList();
        Device data1 = new Device(1);
        Device anotherData1 = new Device(1);
        list.add(data1);
        System.out.println(list.contains(data1)); // true
        System.out.println(list.contains(anotherData1)); // false
    }
}
但是,如果您在设备旁边添加以下代码,则此代码将起作用(两次都打印为 true):
        @Override
        public boolean equals(Object obj) {
            if (obj == null || getClass() != obj.getClass()) {
                return false;
            }
            return this.value == ((Device) obj).value;
        }
        @Override
        public int hashCode() {
            return 7 + 5*value; // 5 and 7 are random prime numbers
        }
在此处查看更多详细信息:在 Java 中覆盖 equals 和 hashCode 时应考虑哪些问题?