请帮我解决一下这个。我想通过array2的元素扫描array1,如果在array1中找到它,则忽略array2的元素。所以只会留下一份水果清单。但输出显示:球,铅笔。我希望它只显示水果中的元素。感谢您的帮助
import java.util.*;
public class CountFruits
{
public static void main(String args[])throws Exception
{
String array1[] = {"apple", "mango", "orange", "banana", "ball", "pencil"};
String array2[] = {"ball", "pencil"};
List<String> fruits = new ArrayList<String>();
for(int x = 0; x < array1.length; x++)
{
for(int y = 0; y < array2.length; y++)
{
if(array1[x].equals(array2[y]))
{
System.out.println(array1[x] + "\t" + array2[y]);
if(!fruits.contains(array1[x]))
{
fruits.add(array1[x]);
}
}
}//end for
}//end for
System.out.println("fruits: " +fruits);
}
}