String str1 = "ABCDE";
String str2 = "abcde44";
// 字符转换成数组 char[] arr1 = str1.toCharArray(); char[] arr2 = str2.toCharArray();
System.out.println(arr1); System.out.println(arr2);
// 获取数组长度
int i = arr1.length;
int j = arr2.length;
int count ;
// 遍历数组
if (i > j) {
count =i;
} else {
count = j;
}
List<Character> list = new ArrayList<Character>();
for (int x=0;x<count;x++){
if(x<i){
list.add((arr1[x]));
}
if(x<j){
list.add((arr2[x]));
}
}
//定义最终字符串
String s="";
for (Character cha : list) {
s=s+cha;
}
//获取结果
System.out.println(s);
}
时间: 2024-08-24 17:17:29