package cn.dadongzicool.string;
import java.util.Iterator;
import java.util.Scanner;
import java.util.TreeSet;
public class TestString {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
TreeSet<Array> a = new TreeSet<Array>();
TreeSet<Array> b = new TreeSet<Array>();
Scanner reader = new Scanner(System.in);
Array array;
int a_num,b_num,sum = 0;
System.out.println("请输入数组a的元素个数");
a_num = reader.nextInt();
System.out.println("请输入数组a的元素");
for(int i = 0;i < a_num;i++){
array = new Array(reader.nextInt());
a.add(array);
}
System.out.println("请输入数组b的元素个数");
b_num = reader.nextInt();
System.out.println("请输入数组b的元素");
for(int i = 0;i < b_num;i++){
array = new Array(reader.nextInt());
b.add(array);
}
Iterator<Array> a_array = a.iterator();
while(a_array.hasNext()){
Array array_a = a_array.next();
Iterator<Array> b_array = b.iterator();
while(b_array.hasNext()){
Array array_b = b_array.next();
if(array_a.num == array_b.num){
sum++;
}
}
}
System.out.println(sum);
}
}
*******************************************************************************
package cn.dadongzicool.string;
public class Array implements Comparable{
int num = 0;
Array(int num){
this.num = num;
}
public int compareTo(Object b) {
// TODO Auto-generated method stub
Array array = (Array)b;
return this.num - array.num;
}
}