public static void main(String args[])
{
byte[] bytearray = new byte[]{1, -30, 48, 50, 49, 48};
for (int i = 0; i < bytearray.length; i++) {
System.out.print(bytearray[i]+", ");
}
System.out.println();
System.out.println("Length of byteArray before : "+bytearray.length);
String st = new String(bytearray);
System.out.println("String value : "+ st);
bytearray = st.getBytes();
for (int i = 0; i < bytearray.length; i++) {
System.out.print(bytearray[i]+", ");
}
System.out.println();
System.out.println("Length of byteArray after : "+bytearray.length);
}
this is my program if i am executing this on windows i am getting exactly same bytes as previous but on ubuntu, it's giving extra 2 bytes I didn't understand it ? why ?
which method should I use to get same array on ubuntu ?
new String(bytearray, "UTF-8")andstr.getBytes("UTF-8").