package generic;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;

public class ComparableDemo {

	public static void main(String[] args) {
		// Comparable
		// 内置应用类型的比较
		Integer integer;
		Character character;
		String string;
		
		Date data = new Date();
		
		// 自定义类型
		// List转为Array之后再进行比较
		String[] arr = {"a","bc","abc"};
		System.out.println((Comparable)arr[0].compareTo("acd"));
		
		
		
		
		// Comparator 独立与实体类；方便实现各种规则
		// 使用Comparator排序数组
		
		// 
		Collections.sort(new ArrayList<String>());
		
		
		
	}
}

class StringComp implements Comparator<String> {

	@Override
	public int compare(String o1, String o2) {
		
		int len1 = o1.length();
		int len2 = o2.length();
		
		return len1 - len2;
	}

	
}







@@ -11,16 +11,45 @@
 neric;%0A%0A
+import java.util.ArrayDeque;%0A
 import j
@@ -68,16 +68,16 @@
 ayList;%0A
-
 import j
@@ -174,16 +174,124 @@
 il.Date;
+%0Aimport java.util.Queue;%0Aimport java.util.TreeMap;%0Aimport java.util.TreeSet;%0A%0Aimport javax.management.Query;
 %0A%0Apublic
@@ -724,30 +724,407 @@
 String%3E());%0A
-
 %09%09%0A%09%09%0A
+%09%09// TreeSet %E4%BD%BF%E7%94%A8%E5%B8%A6%E6%AF%94%E8%BE%83%E5%99%A8%E7%9A%84%E6%9E%84%E9%80%A0%E6%96%B9%E6%B3%95%0A%09%09StringComp stringComp = new StringComp();%0A%09%09TreeSet treeset = new TreeSet(stringComp);%0A%09%09%0A%09%09treeset.add(%22b%22);%0A%09%09treeset.add(%22ab%22);%0A%09%09treeset.add(%22abc%22);%0A%09%09treeset.add(%22bcd%22);%0A%09%09treeset.add(%22abcd%22);%0A%09%09%0A%09%09System.out.println(%22treeset:%22+treeset);%0A%09%09%0A%09%09// TreeMap %E5%90%8C%E4%B8%8A%0A%09%09TreeMap treeMap = new TreeMap(stringComp);%0A%09%09%0A%09%09%0A%09%09Queue queue = new ArrayDeque();%0A%09%09%0A
 %09%09%0A%09%7D%0A%7D%0A%0Acla

change Compara demo