... List<Device> devices = new ArrayList<>(); ... ... Collections.sort(devices, new Comparator<Device>() { @Override public int compare(Device o1, Device o2) { return o1.id-o2.id; } }); ... ...