how to compare a char to a string java

Solutions on MaxInterview for how to compare a char to a string java by the best coders in the world

showing results for - "how to compare a char to a string java"
Alonso
17 Jan 2019
1public class JavaCharacterCompareExample1 {
2	public static void main(String[] args) {
3		char firstValue = 'A';
4		char secondValue = 'B';
5		// compare the first char to the second
6    	int result = Character.compare(firstValue, secondValue);
7    	if (result == 0) {
8      		System.out.println("The chars are the same.");
9    	} else {
10          	System.out.println("The chars are different.");
11        }
12	}
13}