I have a list of objects and I would like to sort it with a defined order.
For ex. I have an object with a field String color. I would like to sort my list on the color field so that it always has first white than blue than yellow and than all the others(if possible alph. ordered but not necessary):
Before sorting: After sorting:
orange white
white blue
green yellow
brown orange
yellow black
black brown
... ...
Is there a (easy) way to do that?
EDIT:
I have to add a complication more...
What if there can be more colors with the same name/radix? For ex. whiteX, whiteY, whiteZ, blueA, blueB, ...
All the whites must come first than all the blues than all the yellows and than all the others. It is still possible to solve that with a comparator? (I can't imagine how...)