I'd like to ask if anyone knows how to append a byte to an array of bytes..I tried the following:1:byte[] a;// some operation to give array "a" a some valuesbyte b;// some operations to give "b" a valuebyte c[a.length + 1];c = a;c[a.length + 1] = b;2:byte[] a;// some operation to give array "a" a some valuesbyte b;// some operations to give "b" a valuebyte c[];c = a;c[a.length + 1] = b;none of them worked.
your statements will not work1: c = a;2: c[a.length + 1] = b;i guess in 2: you must be getting ArrayIndexOutOfBoundsExceptionfollowing will workbyte [] c= new byte[a.length+1];for(int i=0;i<a.length;i++) c[i]=a[i];c[a.length]=b;
Unless you have to use the array notation, you may want to look at theVector or ArrayList classes. They automatically handle resizing, butyou have to use the wrapper classes and casts (at least until Java 1.5is released).