:
Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
, , . :
public int compare(Integer o1, Integer o2) {
if(o1.intValue() < o2.intValue())
return -1;
if(o1.intValue() > o2.intValue())
return 1;
return 0;
}
, , , , , , 0.
, - :
public int compare(String o1, String o2) {
if(o1.equals(o2))
return 0;
if(o1.equals("ordinary") && o2.equals("premium"))
return 1;
if(o1.equals("premium") && o2.equals("ordinary"))
return -1;
return 0;
}
, 0. "", -1, "", 1.
, . , , . - .
"" "", :
public int compare(String o1, String o2) {
if(o1.equals(o2))
return 0;
if(o1.equals("ordinary") || o2.equals("premium"))
return 1;
if(o1.equals("premium") || o2.equals("ordinary"))
return -1;
return 0;
}
, , o1 "", 1, , o2 "", -1, . "".