找出两个数组中不同的元素
程序员文章站
2024-01-06 14:02:40
...
import java.util.Arrays;
/**
* 找出两个数组中不同的元素
* @datetime Dec 24, 2009 5:34:55 PM
* @author 聂靖宇
* @email [email protected]mail.com
* @msn [email protected]
* @QQ 6241899
* @description
*/
public class TestArray {
public static void main(String[] args) {
int[] a = new int[]{2, 5, 4, 3};
int[] b = new int[]{1,3, 4, 5};
Arrays.sort(b);
Arrays.sort(a);
TestArray test = new TestArray();
test.getDelArr(a, b);
test.getAddArr(a, b);
}
public void getDelArr(int a [],int b[]){
System.out.println("a有b没有:");
for( int i = 0, size = a.length; i < size; i++ ) {
int index = Arrays.binarySearch(b, a[i]);
if( index < 0 ) {
System.out.println(a[i]);
}
}
}
public void getAddArr(int a [],int b[]){
System.out.println("b有a没有:");
for( int i = 0, size = b.length; i < size; i++ ) {
int index = Arrays.binarySearch(a, b[i]);
if( index < 0 ) {
System.out.println(b[i]);
}
}
}
}
作者:小屁孩
Q Q:6241899
Q Q群:28187997,76434335,72217599
网址:http://xiaopihai.iteye.com/blog/555970
>>> 版权所有,转载请注明出处!<<<