0

如果像这样创建可以正常工作:

byte [] d = {1,2};
String ss = new String( d );

但是如果像这样创建会失败:

String ss = new String( {1,2} );

甚至这个:

String ss = new String( {(byte)1,(byte)2});

问题是什么?

4

2 回答 2

3

String ss = new String( new byte[]{1,2} );

String ss = new String( {1,2} );不起作用,因为无法通过简单地执行{}块来初始化数组。它需要new someThing[]在它的前面。

于 2013-10-25T12:28:45.790 回答
0
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} );
于 2013-10-25T12:39:22.903 回答