//companys 是一個List對象集合 Collections.sort(companys, new Comparator() { public int compare(Object a, Object b) { Long one = ((UserCompany) a).getCompany().getComid(); Long two = ((UserCompany) b).getCompany().getComid(); return (int) (one - two); } });