Java Convert Object[] Array to Vector

后端 未结 6 2026
灰色年华
灰色年华 2020-12-16 19:21

What\'s the best way to convert an Object array to a Vector?

JDE < 1.5

public Vector getListElements()
{
  Vector myVector = this.elements;
  retu         


        
6条回答
  •  暖寄归人
    2020-12-16 20:04

    A simplified comparator which does basically the same thing.

    final static class ContactsListComparatorByFirstName implements Comparator {
        public int compare(Object o1, Object o2) {
                // Sticky Entries Implementation
            ContactsListObject clo2 = (ContactsListObject) o2;
            ContactsListObject clo1 = (ContactsListObject) o1;
            if (clo2.getSticky()) return 1;
            if (clo1.getSticky()) return -1;
            return clo1.get_contactFirstName().compareTo(clo2.get_contactFirstName());
        }
    }    
    

    Using generics and ?: it would be just

    static final class ContactsListComparatorByFirstName implements Comparator {
        public int compare(ContactsListObject clo1, ContactsListObject clo2) {
            return clo2.getSticky() ? 1 : // Sticky Entries Implementation
                clo1.getSticky() ? -1 :
                clo1.get_contactFirstName().compareTo(clo2.get_contactFirstName());
        }
    }
    

    But to answer your question... (oh I see Tom has what I would put already)

提交回复
热议问题