java对比两个数组

 
package com.call.comm;

import java.util.*;

public class ts {
    
	public static void main(String[] args)
	{

		String[] a={"2012A","2014A","2013A","2212A","E24A2","E34A3"};
		String[] b={"2013A","2014A","2012A","2212A","22222","11111","33333"};
		List<String> list=new ArrayList<String>();
		for(int i=0;i<b.length;i++)
		{
			list.add(b[i]);
		}
	
		List<String> bthana=new ArrayList<String>();
		List<String> diforder=new ArrayList<String>();
		bthana=more(a,b);
		System.out.println("【b比a多】:");
		for (String s : bthana) {
		//System.out.println(s);
		list.remove(s);
		}
		for(int i=0;i<list.size();i++)
		{
			System.out.println(list.get(i));
		}
		bthana=more(b,a);
		System.out.println("----------");
		System.out.println("【b比a少】:");
		for (String s : bthana) {
		System.out.println(s);
		}
	}
	public static List<String> more(String[] b,String[] a){
		List<String> temp=new ArrayList<String>();
		int t=0;
		String tempString="";
		boolean exist=false;
		for(int a1=0;a1<a.length;a1++){
		for(int b1=0;b1<b.length;b1++){
		if(a[a1].equals(b[b1])){
		exist=true;
		break;
		}else{
		exist=false;
		tempString=a[a1];
		}
		}
		if(!exist){
		temp.add(t, tempString);
		t++;
		}
		}
		return temp;
		}


}

你可能感兴趣的:(java,String,list,Class)