小编Fai*_*ood的帖子

表达式的类型必须是数组类型,但它解析为ArrayList(尝试比较两个数组中的字符串)

我试图将数组中的每个字符串或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 …
Run Code Online (Sandbox Code Playgroud)

java arrays string loops for-loop

8
推荐指数
2
解决办法
6万
查看次数

标签 统计

arrays ×1

for-loop ×1

java ×1

loops ×1

string ×1