java 双重遍历_java 双重循环

你如果a1有2 ,b1也有2,是把a1,b1的都放进c1吗?

你看这样了。

import java.util.ArrayList;

/**

* @ClassName: Test

* @Description: Test the double circular

* @author :

* @date May 23, 2012 5:49:01 PM

*

*/

public class Test {

/**

* @Title: main

* @Description: Main method the program entry

* @param args

* @return void

* @throws

*/

public static void main(String[] args) {

List a1 = new ArrayList();

a1.add("2");

a1.add("3");

a1.add("5");

a1.add("4");

a1.add("6");

a1.add("8");

List b1 = new ArrayList();

b1.add("4");

b1.add("2");

b1.add("5");

b1.add("6");

b1.add("8");

List c1 = new ArrayList();

if (a1.contains("2") && b1.contains("2")) {

for (int j = 0; j < a1.size(); j++)

c1.add(a1.get(j));

for (int x = 0; x < b1.size(); x++)

c1.add(b1.get(x));

}

if (a1.contains("2") && !b1.contains("2")) {

System.out.println("ERROR...");

System.exit(0);

}

if (!a1.contains("2")) {

for (int i = 0; i < b1.size(); i++) {

//for (int m = 0; m < a1.size(); m++) {

//if (b1.get(i).equals(a1.get(m))) {

//c1.add(a1.get(m));

c1.add(b1.get(i));

//}

//}

}

}

for (int k = 0; k < c1.size(); k++)

System.out.println("c1[" + k + "]= " + c1.get(k));

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值