`
空空儿
  • 浏览: 134989 次
  • 性别: Icon_minigender_2
  • 来自: 杭州
社区版块
存档分类
最新评论

找出两个数组不同的数据

    博客分类:
  • J2SE
阅读更多
找出num2在num1中没有的数值。

public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        int [] num1 = new int[]{1,2,3};
        int [] num2 = new int[]{1};
        
        for(int i = 0; i < num1.length; i ++){
            boolean status = false;
            for(int j = 0; j < num2.length; j ++){
               if(num1[i] == num2[j]){
                   status = true;
                   break;
               }
            }
            if(!status){
                System.out.println(num1[i]);
            }
        }
    }
}
0
0
分享到:
评论
1 楼 zachary.guo 2010-08-24  
把数组转成 List,利用 apache 的 CollectionUtils 的集合求交集的方式,可以省去自己对数组的操作。交集得到了,后面的就容易了,集合有 remove 的行为。

相关推荐

Global site tag (gtag.js) - Google Analytics