Compare two char value in Java
Description
The following code shows how to compare two char value.
Example
//from www. j av a 2s. co m
public class Main {
public static void main(String[] args) {
Character c1 = new Character('6');
Character c2 = new Character('7');
char c3 = c1.charValue();
char c4 = c2.charValue();
if (c3 < c4)
System.out.println(c3 + " is less than " + c4);
if (c1.compareTo(c2) < 0)
System.out.println(c1 + " is less than " + c4);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »