Character.charValue() vs toString in JAVA -


what difference between charvalue() , tostring() methods of class character. both of them return same i.e, character value held object of class character in following code.

public class othercharmethods  {     public static void main(string[] args)    {       character c1 = 'a';       character c2 = 'a';        system.out.printf(             "c1 = %s\nc2 = %s\n\n", c1.charvalue(), c2.tostring());        if (c1.equals(c2))       system.out.println("c1 , c2 equal\n");       else       system.out.println("c1 , c2 not equal\n");      }   } // end class othercharmethods 

the 1 method returns single char value (primitive type); other 1 returns string (reference type).

that there this.

given comment: thing understand - returned string of course contain one character; 1 charvalue() returns you.

but: still 2 different things. literals "a" , 'a' contain 1 char; in end mean different things. if print variables system.out; of course gives same result. doesn't make char same string.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -