How to concatenate two char arrays in java ?
char info[]=new char[10]; char data[]=new char[10]; char result[]=new char[40]; I need to concatenate info and data, and store the concatenation in result:
result=info+data;
How to do this?
How to concatenate two char arrays in java ?
char info[]=new char[10]; char data[]=new char[10]; char result[]=new char[40]; I need to concatenate info and data, and store the concatenation in result:
result=info+data;
How to do this?
It depends I guess. The simpler approach would be just to convert the char arrays to a String and concaternate the Strings.
A better approach would be to use StringBuilder
char info[] = new char[10]; char data[] = new char[10]; // Assuming you've filled the char arrays... StringBuilder sb = new StringBuilder(64); sb.append(info); sb.append(data); char result[] = sb.toString().toCharArray(); result. He says he wants result = info + data. In your case, the last line should be result = sb.toString().toCharArray();sb.toString().toCharArray() to get the character array back. This of course assumes the OP wants to only use char arrays ;)Just found one-line solution from the old Apache Commons Lang library: ArrayUtils addAll()