【问题标题】:Add a list of integers into a csv file (JAVA)将整数列表添加到 csv 文件 (JAVA)
【发布时间】:2020-07-18 23:59:52
【问题描述】:

我想要的只是从算法中添加一个数字列表(这真的很长,所以我不会在这里展示它,但给出的输出是 [2039, 25553, 189030, 1449869, 134295, 352258, 1588788, 718293 , 353578, 1495712, 539563, 1691741, 1032543, 362844, 1143463, 4671463])

List<Integer> List1 = new ArrayList<>();

到 csv 文件并从中生成折线图。 我已经做了一些寻找答案,但我找不到任何具体的东西。 任何帮助将不胜感激,谢谢!

【问题讨论】:

    标签: java arraylist statistics export-to-csv


    【解决方案1】:
    public class Try
    {
        public static void main(String[] args) throws IOException
        {
            List<Integer> List1 = new ArrayList<>();
    
            //For the example, i populate the list
            List1.add(123);
            List1.add(456);
            List1.add(789);
    
            PrintWriter outFile = new PrintWriter(new FileWriter("outNumbers.csv"));
    
            List1.stream().forEach(i->outFile.print(i + ", "));
    
            outFile.close();
        }
    }
    

    【讨论】:

    • 对资源使用 try 会更好。或者在 finally 块关闭蒸汽。
    • 您好,感谢您的回答,非常感谢。另外,我怎么能把这个列表放在一个格式化的表格中,用 y 和 x 轴详细说明它们的值?这样代码List1.add(123); List1.add(456); List1.add(789); 可以在表格中格式化,因此 123 可以在名为“one”的行上的名为“one”的列下
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多