Java Comparator for Objects with multiple fields [closed]
I have an Object Collection with 5 fields: id; entityType; entityId; brandId; productId; To sort an ArrayList of Collection I have written the following Comparaor . Comparator<Collection> collectionComparator = new Comparator<Collection>() { @Override public int compare(Collection collection1, Collection collection2) { if(collection1.getId().equals(collection2.getId())) { if(collection1.getEntityType().equals(collection2.getEntityType())) { if(collection1.getEntityId().equals(collection2.getEntityId())) { if(collection1.getBrandId().equals(collection2.getBrandId())) { return collection1