concat - is there a bug in java new String -


i try code:

byte[] data = new byte[66000]; int count = is.read(data); string srequest = new string(data);  //will received byte array hello string = srequest;         = all.concat("world"); system.out.println(all); 

it print console: hello

concat funtion of java have bug? used + operator instead concat function result same :( how can concat string new string byte array?

instead of

    string srequest = new string(data);  //will received byte array hello 

use

    string srequest = new string(data, 0, count);  //will received byte array hello 

you notice difference when additionally print length of result string:

    system.err.println(all + "/" + all.length()); 

gives helloworld/66005 in first case , helloworld/10 in second case. reason see "hello" might issue of console - in eclipse, see "helloworld" when copy&paste editor 1 of words taken. 0 values initial array part of result (since had been added first string), not printed out (since not printable characters).


Comments

Popular posts from this blog

Receive udp packets in android gstreamer -

php - Extract Text from HTTP referer -

matplotlib - PYTHON: Annotate boxes disapear dependant on range -