Java string comparison | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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 Answers
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