开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜