Java - 拆分 ArrayList

Java - Splitting ArrayList

大家好我正在尝试扫描文本文件的底部 6 行并将它们显示在 JOptionPane.showMessageDialog 当前显示为 [line7, line6, line5, line4, line3, line2] 我希望它显示为垂直列表而不是逗号分隔符。

ArrayList<String> bandWidth = new ArrayList<String>();
FileInputStream in = null;
try {
    in = new FileInputStream("src/list.txt");
} catch (FileNotFoundException e) {
    e.printStackTrace();
}
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String tmp;
try {
    while ((tmp = br.readLine()) != null)
    {
        bandWidth.add(tmp);
        if (bandWidth.size() == 7)
            bandWidth.remove(0);
    }
} catch (IOException e) {   
    e.printStackTrace();
}
ArrayList<String> reversedSix = new ArrayList<String>();
for (int i = bandWidth.size() - 1; i >= 0; i--)
    reversedSix.add(bandWidth.get(i));
                                                            JOptionPane.showMessageDialog(null,bandWidth,null,JOptionPane.INFORMATION_MESSAGE);

尝试循环 ArrayList 并生成带有换行符的 String

String result = "";
for (int i = 0; i < bandWidth.size(); i++)
{
    result += bandWidth.get(i) + "\n";
}
JOptionPane.showMessageDialog(null,result ,null,JOptionPane.INFORMATION_MESSAGE);

注意:如果这是输出 HTML,则使用 <br \> 而不是 \n