⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testsort.java

📁 一些Java写的测试API的源代码
💻 JAVA
字号:
/**
 *Author Miracle
 *Time 2005.12.4 19:40
 *
 */

/**  implements Comparator   **/ 

/**  implement the sort(Num,String) by implementing the Comparator interface **/

import java.util.*;

public class TestSort 
{
	public static void main(String[] args)
	{
		List l = Arrays.asList(args);
		Collections.sort(l,new YourComparator());
		System.out.println(l);
	}
}

/**   sort the Number **/
class MyComparator implements Comparator
{
	public int compare(Object o1,Object o2)
	{
		int s1 = Integer.parseInt(o1.toString());
		int s2 = Integer.parseInt(o2.toString());
		return  s1 > s2?1:(s1==s2?0:-1);

	}
}

/** sort the String by theFirst char **/
class YourComparator implements Comparator
{
	public int compare(Object o1,Object o2)
	{
		String s1 = o1.toString();
		String s2 = o2.toString();
		return s1.charAt(0) > s2.charAt(0)?1:(s1.charAt(0)==s2.charAt(0)?0:-1);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -