我试图将数组中的每个字符串或 int 与另一个数组进行比较,然后根据另一个数组中是否存在该字符串来打印结果: 下面是整个代码:尝试比较两个值时,我在 for 循环中出错.equals(不确定它是否正确,...我是新手)请帮忙!
public class comparer {
public void compare (){
ArrayList NameofFileinDir = new ArrayList ();
ArrayList Stocks = new ArrayList();
// populate array with files names in dir
try {
Scanner reads = new Scanner (new File("G:/Programming/StockDataDownload/NameOfFileinDir.txt"));
String FileCode;
while (reads.hasNext()){
FileCode = reads.nextLine(); //read next line
NameofFileinDir.add(FileCode);
}
reads.close();
}
catch (IOException e) {
}
// populate array with original stocks
try {
Scanner reads = new Scanner (new File("G:/Programming/StockDataDownload/AllSecurities.txt"));
String StockCode;
while (reads.hasNext()){
StockCode = reads.nextLine(); //read next line
Stocks.add(StockCode);
}
reads.close();
for(int i = 0; i < Stocks.size(); i++) {
for (int j = 0; j < NameofFileinDir.size(); j++) {
if (Stocks[i].equals(NameofFileinDir[j])) > 0) {
System.out.println("Stock:" + Stocks[i]);}
else{
System.out.println("Stock not in files:" + Stocks[i]);
}
}
}
}
catch (IOException e) {
}
}}