import java.util.ArrayList;
import java.util.List;
public class TranData {
private static String[] totalARR=null;
private static String[] dn0=null;
private static String[] scr=null;
/**
* @param args
*/
public static void main(String[] args) {
List<String[]> list=new ArrayList();
//第一个是类别号dn0[0] 第二个是内容数量dn0[1]
String[] dn0={"1","3","a","b","c"};
String[] dn1={"1","4","e","r","t","t"};
String[] dn2={"2","2","d","e"};
list.add(dn0);
list.add(dn1);
list.add(dn2);
//send=======>
dn0=TransSendUtils(list);
System.out.print("Before send : ");
for(int j=0;j<dn0.length;j++){
System.out.print(dn0[j]+" ");
}
System.out.println();
List<String[]> list2=new ArrayList();
//receive============>
list2=TransReceiveUtils(dn0);
System.out.println("After Get :");
for(int j=0;j<list2.size();j++){
String[] number=(String[])list2.get(j);
for(int i=0;i<number.length;i++){
System.out.print(number[i]+" ");
}
System.out.println();
}
}
/**
* receive
* @param String[]
* @return
*/
public static List<String[]> TransReceiveUtils(String[] arr){
List<String[]> list=new ArrayList();
for(int arrsize=arr.length;arrsize>0;){
int indx=Integer.parseInt(arr[1])+2;
dn0=new String[indx];
scr=new String[arrsize-indx];
System.arraycopy(arr,0,dn0,0,indx);
System.arraycopy(arr,indx,scr,0,arrsize-indx);
arrsize=arrsize-indx;
arr =new String[arrsize];
arr=scr;
list.add(dn0);
}
return list;
}
/**
* send
* @param List<String[]>
* @return
*/
public static String[] TransSendUtils(List<String[]> list){
int listSize=list.size();//得到每个集合中放的元素的个数
String[] newArray=null;
String[] tempArr=null;
int cou=0;
int couA=0;
for(int i=0;i<listSize;i++){
String[] number=(String[])list.get(i);
cou=number.length;
couA+=cou;
newArray=new String[cou];
if(tempArr==null){
tempArr=new String[couA-cou];
}
System.arraycopy(number,0,newArray,0,cou);
totalARR=new String[couA];
System.arraycopy(tempArr,0,totalARR,0,couA-cou);
System.arraycopy(newArray,0,totalARR,couA-cou,cou);
tempArr=totalARR;
}
return totalARR;
}
}
--------结果-------
Before send : 1 3 a b c 1 4 e r t t 2 2 d e
After Get :
1 3 a b c
1 4 e r t t
2 2 d e