我正在尝试从 txt 文件中打印出索引,并且我正在使用扫描仪读取下面的文件我似乎在将单词放入数组列表中时遇到了问题
public class Concordance
{
public static void main (String[]args) throws IOException
{
TreeMap <String, ArrayList<Integer>> concordance = new TreeMap <String, ArrayList<Integer>>();
File myfile = new File ("Caesar.txt");
Scanner scan = new Scanner(myfile);
ArrayList <Integer > integer = new ArrayList <Integer>();
for (int i = 0; i < scan.nextLine().length(); i++)
{
String key = scan.nextLine().toLowerCase();
if (scan.nextLine().length(i) > 1)
{
if (concordance.get(key) == null) {
concordance.put(key, 1))
} else {
ArrayList<Integer> value = concordance.get(key).indexOf(integer);
value++;
concordance.put(key, value);
}
}
}
System.out.println(concordance);
}
}