work119.java
package test06;
public class work119
{
enum Constants4
{
A,
B,
C,
D
}
public static void compare(Constants4 c)
{
for (int i = 0; i < Constants4.values().length; i++)
{
System.out.println(c + "与" + Constants4.values()[i] + "的比较结果为:" + c.compareTo(Constants4.values()[i]));
}
}
public static void main(String[] args)
{
work119.compare(Constants4.valueOf("B"));
}
}
/*
* 调用枚举类型Constants4.compareTo方法的结果,
* 正值表示该对象之前,
* 0表示位置相同,
* 负值表示该对象之后
*
*/