Suppose I have two classes CLassA and CLassB. And they have one atributte in common, for example the number of elements that each class holds.
How can i create a collect
Hmm.. is it possible for ClassA and ClassB to share an interface?
interface InterfaceZ
{
int getCount();
}
class ClassA implements InterfaceZ
{
int getCount() { return _myArray.length; }
}
class ClassB implements InterfaceZ
{
int getCount() { return _complexCollection.size(); }
}
Then just sort the list like so:
List myArray;
... fill up array ...
Collections.sort(myArray, new Comparator() {
public int compare(InterfaceZ o1, InterfaceZ o2) {
return o2.getCount() - o1.getCount();
}});