import java.util.Iterator
import java.util.List
public class TestBaiduKnow {
public static void main(String[] args) {
List<Object> a = new ArrayList<Object>()
a.add("1")
a.add("2")
a.add("3")
a.add("4")
a.add("5")
List<Object> b = new ArrayList<Object>()
b.add(6)
b.add(7)
b.add(8)
b.add(9)
List<Object> c = new ArrayList<Object>()
Object[] aa = a.toArray()
Object[] ba = b.toArray()
int cnt = 0
int i = 0
int j = 0
while (i < aa.length) {
c.add(aa[i])
cnt += 1
if (cnt % 2 == 0 && j < ba.length) {
c.add(ba[j])
cnt = 0
j += 1
}
i += 1
if (i == aa.length) {
while (j < ba.length) {
c.add(ba[j])
j += 1
}
}
}
a.clear()
a = c
Iterator<Object> it = a.iterator()
while (it.hasNext()) {
System.out.print(it.next() + " ")
}
}
}
//声明一个集合 List list = new List()//声明一个数组string[] Array = new string[] { }//接受集合遍历出来的数据 string str = ""//给集合添加数据
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)