+ 1

Java string comparison

Hello! I have written a code in which there is a character x . Now during writing an if statement, i am converting this char to string before comparison but still code is showing no output. Here's the code public class Program { public static void main(String[] args) { char x='a'; if(Character.toString(x)=="a"){ System.out.print("hello"); } } }

16th Jun 2022, 1:37 PM
Adnan Ur Rehman
Adnan Ur Rehman - avatar
2 odpowiedzi
16th Jun 2022, 3:09 PM
A͢J
A͢J - avatar
+ 2
Thanks everyone . Now i understood it.
16th Jun 2022, 3:23 PM
Adnan Ur Rehman
Adnan Ur Rehman - avatar