I'm trying to get the information from Stock.txt and to transfer it into an array of strings, each index being a new line in the file. I get a warning:
Duplicate local variable. What is the problem, is it out of scope?
public static List<String> getStock(List<String> stockText){
Scanner scanner = null;
try {
File input = new File("Stock.txt");
scanner = new Scanner(input);
String[] info = null;
while (scanner.hasNextLine()) {
info = scanner.nextLine().split(",");
}
List<String> stockText = Arrays.asList(info);
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
finally {
scanner.close();
}
return stockText;
}
}
stockTextis the name of your input parameter and the local variable you create inside thetryblockstockTextas a parameter to the method and then create another local variable with the same name. You never use the paremeter so you can remove it from the declaration.