The issue is to sort a huge collection of POJO objects
class Entity{
String key1;
String key2;
String key3;
String key4;
}
in alphabetical order by all of fields subsequently. That means that first we are sorting by key1, then by key2 and etc. Any of that key can be null. The question is the simplest way to do that.
A good way to do
append all keys togetherand then use aComparator<Entity>–What i am doing here is….. all the keys of an entity are appended together in the order in which comparison need to be done, and then compared with the other entity.
you might also need to trim each value before appending.
EDITED:
It is also necessary to seperate each key by
spacefor code to work properly.Code fixed above. Thanks @Thilo for pointing it.