Take a character from a string as an array element
Public class mainclass {
Public static void main (string [] arg ){
String text = "to be or not to be"; // define a string
Byte [] textarray = text. getbytes ();
For (byte B: textarray ){
System. out. println (B );
}
}
Add value to data
Class substringcons {
Public static void main (string args []) {
Byte ascii [] = {65, 66, 67, 68, 69, 70 };
String s1 = new string (ascii );
System. out. println (s1 );
String s2 = new string (ascii, 2, 3 );
System. out. println (s2 );
}
}
Convert to byte to a hexadecimal string
Import java. io. unsupportedencodingexception;
/**
* Format validation
*
* This class encodes/decodes hexadecimal data
* @ Author jeffrey rodriguez
* @ Version $ id: hexbin. java 125124 00: 23: 54z kkrouse $
*/
Public class main {
Static private final int baselength = 255;
Static private final int lookuplength = 16;
Static private byte [] hexnumbertable = new byte [baselength];
Static private byte [] lookuphexalphabet = new byte [lookuplength];
Static {
For (int I = 0; I <baselength; I ++ ){
Hexnumbertable [I] =-1;
}
For (int I = '9'; I> = '0'; I --){
Hexnumbertable [I] = (byte) (I-'0 ');
}
For (int I = 'F'; I> = 'a'; I --){
Hexnumbertable [I] = (byte) (I-'A' + 10 );
}
For (int I = 'F'; I> = 'a'; I --){
Hexnumbertable [I] = (byte) (I-'A' + 10 );
}
For (int I = 0; I <10; I ++)
Lookuphexalphabet [I] = (byte) ('0' + I );
For (int I = 10; I <= 15; I ++)
Lookuphexalphabet [I] = (byte) ('a' + I-10 );
}
/**
* Converts bytes to a hex string
*/
Static public string bytestostring (byte [] binarydata)
{
If (binarydata = null)
Return null;
Return new string (encode (binarydata ));
}
/**
* Array of byte to encode
*
* @ Param binarydata
* @ Return encode binary array
*/
Static public byte [] encode (byte [] binarydata ){
If (binarydata = null)
Return null;
Int lengthdata = binarydata. length;
Int lengthencode = lengthdata * 2;
Byte [] encodeddata = new byte [lengthencode];
For (int I = 0; I <lengthdata; I ++ ){
Encodeddata [I * 2] = lookuphexalphabet [(binarydata [I]> 4) & 0xf];
Encodeddata [I * 2 + 1] = lookuphexalphabet [binarydata [I] & 0xf];
}
Return encodeddata;
}
}