java 冒泡排序 String类型日期

package payton;

/**
 * @author payton
 * @version 创建时间:Nov 19, 2014 6:19:45 PM 类说明
 * 
 * String类型日期数据冒泡排序
 */

public class StringDateCompare {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		String[] date = new String[] { "2014-10-01", "2013-10-12",
				"2013-04-23", "2013-04-23", "2014-12-12", "2013-08-24",
				"9999-12-12" };
		
		buffSort(date);
		
		for (int k = 0; k < date.length; k++) {
			System.out.println(date[k]);
		}
	}

	public static String[] buffSort(String date[]) {
		String temp = "";
		for (int i = 0; i < date.length - 1; i++) {
			for (int j = 0; j < date.length - 1; j++) {
				if (date[j].compareTo(date[j + 1]) > 0) {
					temp = date[j];
					date[j] = date[j + 1];
					date[j + 1] = temp;
				}
			}
		}
		return date;
	}

}

输出结果:

java 冒泡排序 String类型日期_第1张图片

你可能感兴趣的:(Java)