Apache commons collections 是一套專門針對Collection
進行處理的一系列工具。其中提供了一些Comparactor
,可以針對Collection
來進行處理。這些Comparactor
,大都放在org.apache.commons.collections.comparators
package中。本篇文章主要針對其中的FixedOrderComparator
進行demo:
以下是範例:
String[] data = new String[] { "GUEST", "NORMAL", "NORMAL", "PAID", "VIP", "VIP", "GUEST", "PAID" };
System.out.println(Arrays.toString(data));
Comparator<String> comparator = new FixedOrderComparator(new String[] { "PAID", "VIP", "NORMAL", "GUEST" });
Arrays.sort(data, comparator);
System.out.println(Arrays.toString(data));
[GUEST, NORMAL, NORMAL, PAID, VIP, VIP, GUEST, PAID]
[PAID, PAID, VIP, VIP, NORMAL, NORMAL, GUEST, GUEST]
沒有留言 :
張貼留言