Works fine if creating like this:
byte [] d = {1,2};
String ss = new String( d );
But fails if creating like this:
String ss = new String( {1,2} );
or even this:
String ss = new String( {(byte)1,(byte)2});
What is the problem?
Works fine if creating like this:
byte [] d = {1,2};
String ss = new String( d );
But fails if creating like this:
String ss = new String( {1,2} );
or even this:
String ss = new String( {(byte)1,(byte)2});
What is the problem?
String ss = new String( new byte[]{1,2} );
String ss = new String( {1,2} ); doesn't work because arrays cannot be initialized by simply doing a {} block. It requires the new someThing[] in front of it.
String ss = new String (array of bytes);
we can pass here array of bytes but in
String ss = new String( {1,2} ); {1 , 2} this is not an array and
String ss = new String( {(byte)1,(byte)2}); {(byte)1,(byte)2} this is also not an array
So we can simply use
String ss = new String( new byte[]{1,2} );