when we combine char array with strings in pritln method why char array will converted into byte code in java? -
public class afgh { public static void main(string[] args) { string s2=new string("thisissurya"); char[] buf= new char[30]; s2.getchars(0,4,buf,0); system.out.println(buf); } }
it give output correctly : if change code when write
public class afgh { public static void main(string[] args) { string s2=new string("techfortelangana"); char[] buf= new char[30]; s2.getchars(0,4,buf,0); system.out.println("the chars :"+buf); } }
but giving output: chars :[c@138532dc why char array directly converted string?? when concatenating??!
that's not bytecode
directly printing character array printing array reference string string representation of array.
use arrays.tostring(array)
or iterate on array print array elements.
[c@138532dc
[c
c
means character class[
means array@
@ rate character138532dc
hashcode
ofobject
convertedhexadecimal string
Comments
Post a Comment