String Constructor_networking
One of the constructor defined in String class is String(char chars[],int startindex,int *numChars*)
, but i came across this String(p.getData(),0,p.getLength())
.
Note:p has reference of Da开发者_开发问答tagramPacket Object.
Since getData() returns byte array of data contained in the datagram,it should give an error.But to my surprise it does not give error.
Why is this so? Please explain.
There is a constructor that takes a byte[]
as well:
String(byte[] bytes, int offset, int length)
Constructs a new String by decoding the specified subarray of bytes using the platform's default charset. The length of the new String is a function of the charset, and hence may not be equal to the length of the subarray.
精彩评论