开发者

String Constructor_networking

开发者 https://www.devze.com 2023-02-19 13:10 出处:网络
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()).

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

精彩评论

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

关注公众号