Use ' ' instead of " "

What will happen if I use ’ ’ in joining a character in a string instead of using " ".

I have used ’ ’ here and got 150 instead of getting l* in this program

Let’s consider this lines of codes (Java):

System.out.println("H"+"A"); //HA
System.out.println('H'+'a'); //169
  1. First line is concatenation of H and A that will result in HA (String literal)

  2. Second we are adding the values of two char that according to the ASCII Table H =72 and a =97 that means that we are adding 72+97 it’s like ('H'+'a') .

  3. Let’s consider another case where we would have:

System.out.println("A"+'N');//AN

In this case we are dealing with concatenation of String A and char N that will result in AN .

1 Like